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

Thomas Lindgren <>
Mon Apr 28 16:36:23 CEST 2008

--- Scott Lystig Fritchie <>

> 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?
> "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.

I'll take a look at it. Presumably the negative
constant is parsed as -(1), which is why it's not
considered simple, but I'll have to check. 

The current transformation is pretty straightforward
because it relies on the compiler to take care of code
simplification, but there are at least two ways to get
rid of such errors:

1. Recognize and simplify -(c) into -c before
transforming the code;

2. More generally, detecting that some expression
can't trigger an exception and not emitting handler
code for those. Takes care of -(1) among other things.

Regarding variables appearing in a record declaration,
perhaps one could, as another option, hide the
variable in a closure, the old (fun() -> ... _X ...
end)() trick. I'll have to look at that too.

Finally, the best solution is probably to replace
smart_exceptions with compiler support.


Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

More information about the erlang-questions mailing list