[erlang-questions] Reassigning variables

Thomas Lindgren thomasl_erlang@REDACTED
Tue Mar 17 20:51:50 CET 2009






----- Original Message ----
> From: Matthew Dempsky <matthew@REDACTED>
> ...  I'd like to suggest being able to do
> something like:
> 
>   X = foo(),
>   r(X) = whee(X),
>   r(X) = bar(X),
>   r(X) = xyzzy(X),
>   blah(X).
> 
> where "r(?VAR) = ?EXPR" means to reassign ?VAR to ?EXPR, even if it
> previously has an assigned value.
> 
> Thoughts?  Does anyone have suggestions for better syntax?  I think
> this can be handled with a parse transform, and I'm considering
> writing a parse transform to handle it.  (I haven't checked if anyone
> else has proposed similar functionality in the past, but this is
> something that's been bugging me for a while, and I've finally had to
> rename variables manually enough times to propose this.)

The easy way out is

-define(let(Pat, Val, Body), (fun(Pat) -> Body end)(Val)).

and

?let(X, foo(),
  ?let(r(X), whee(X), 
    ...)).

Best,
Thomas


      




More information about the erlang-questions mailing list