[erlang-questions] Reassigning variables

Hans Bolinder hans.bolinder@REDACTED
Wed Mar 18 10:45:44 CET 2009


[Matthew Dempsky:]
> I like pattern matching in the majority of cases, but I find I write
> enough code where I need to incrementally update a data structure, and
> maintaining that code is a pain when I have code like:
> 
>   X = foo(),
>   X1 = bar(X),
>   X2 = xyzzy(X1),
>   blah(X2).
> 
> and later want to change it to:
> 
>   X = foo(),
>   X1 = whee(X),
>   X2 = bar(X1),
>   X3 = xyzzy(X2),
>   blah(X3).
> 
> This means having to change four lines of code, when really it's
> conceptually just one change.  

Maybe I'm missing the point, but wouldn't a BASIC way of numbering
variables be useful here? It would let you maintain an increasing
sequence of variable names while doing just one change:

  X = foo(),
  X10 = bar(X),
  X20 = xyzzy(X10),
  blah(X20).

and

  X = foo(),
  X5 = whee(X),
  X10 = bar(X5),
  X20 = xyzzy(X10),
  blah(X20).

Best regards,

Hans Bolinder, Erlang/OTP team, Ericsson



More information about the erlang-questions mailing list