[erlang-questions] Record initializer work-around for smart_exceptions?

Scott Lystig Fritchie <>
Fri Apr 25 23:15:39 CEST 2008


Hi.  I suppose this question could be directed to Thomas Lindren, but I
thought I'd share with a wider audience.

Is there a way to avoid these errors (due to introducing temp variables
by the parse transform) when a record initializer contains something
other than a simple term?

    ./foo.erl:0: variable '_0' in record definition
    ./foo.erl:0: variable '_1' in record definition

... in a module like this (using the R11B-5 compiler, at least):

    -module(foo).
    -compile(export_all).
    
    %% -record(foo, { item = 0 }).  % works
    -record(foo, { item = -1 }). % doesn't work
    %% -record(foo, { item = erlang:now() }).  % doesn't work
    %% -record(foo, { item = now() }). % works 
    
    func() -> #foo{}.

"Simple term" is a bit misleading, because -1 appears to be a simple
term in my book, but the hyphen confuses the parse transform.  Much of
the code I'd like to use with smart_exceptions uses negative constants,
unfortunately.

-Scott



More information about the erlang-questions mailing list