[erlang-questions] module params not visible everywhere

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Mon Mar 12 20:36:05 CET 2007


Richard Carlsson wrote:
> 
> > In the case of module parameters, it ought to be safe,
> > since they cannot be redefined.
> 
> They can still be shadowed by locally bound variables in
> fun heads and list comprehension generators, just as if
> you had written:
> 
>      f(X) ->  fun (X) -> #bar{} end.

<blush>
Sometimes fingers outrun brain
</blush>

> > For most users, I guess your proposed workaround is
> > perfectly fine.
> 
> And for you as well: it should be a simple thing to lift all 
> record field initializers to new nullary functions. If you 
> already have a tricky parse transform going, this should be a 
> minor addition to it.

Well, what I ended up doing was to use the annotation
feature in syntax_tools, and indicate whether I was in
the context of a function (a three-liner), and then 
fetching the module parameter via a function call if 
needed outside the scope of a function (another handful
lines of code). The only minor thing to fix now is to
only generate the extra function if it's actually 
referred to (to avoid compiler warnings).

Being able to add annotations to the abstract forms
really simplifies a lot of things.

BR,
Ulf W




More information about the erlang-questions mailing list