[erlang-questions] code_change for gen_fsm: how to actually handle a state change

Barco You barcojie@REDACTED
Tue Nov 22 10:59:55 CET 2011

That would be a great solution!

On Tue, Nov 22, 2011 at 5:54 PM, Ulf Wiger <ulf@REDACTED> wrote:

> On 22 Nov 2011, at 08:49, Barco You wrote:
> > So, that's to say we have to manually change the code_change callback
> whenever we update the state record?
> > It seems to disobey the spirit of simple maintenance by taking the
> advantage of erlang record.
> A feature of 'exprecs' which hasn't been documented, is that it can
> provide a conversion function for old records.
> See for example:
> https://github.com/uwiger/parse_trans/blob/master/examples/test_exprecs_vsns.erl
> This is the output when running it:
> Eshell V5.8.4  (abort with ^G)
> 1> test_exprecs_vsns:f().
> '#info-r'(fields) -> [a,b,c]
> '#info-r__1_1'(fields)' -> [a,b,c,d] (not exported)
> '#info-r__1_2'(fields)' -> [a,b] (not exported)
> '#convert-'("1_1", {r,1,2,3,4}) -> {{r,1,2,3},[{d,4}]}
> '#convert-'("1_1", {r,1,2,3,4}) -> {{r,1,2,undefined},[]}
> ok
> The idea, then, is that old versions of a record definition are kept, and
> renamed with a version suffix (separated from the record name with two
> underscores).
> Exprecs will then automatically generate a '#convert-'/2 function, which
> takes an old record and converts it to the latest definition (the one with
> no version suffix).
> If the old record had more fields than the current, those values are
> returned as a proplist beside the new record. If the old record had fewer
> fields, default values are inserted as usual.
> Note that those old records are expected to have the normal record tag
> ('r', in the case above) - not the tag with a version suffix.
> BR,
> Ulf W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111122/36135b05/attachment.htm>

More information about the erlang-questions mailing list