clarification on single assignment

Erik (Happi) Johansson happi@REDACTED
Thu Nov 23 09:43:36 CET 2000

> Forgetting about matching vs. assignment, wouldn't just defining "x =
> <expr1>;" as having the same semantics as "let x = <expr1> in ..." be
> enough?  In effect, each assignment starts a new variable scope.
> When does
> this fall down?

When you introduce the same var in different branches of a case or if:

case Foo of
  1 -> X = a;
  2 -> X = b;
  _ -> X = c

This kind of use is discourage by the compiler but allowed and can be
rewritten as:
X = case Foo of
      1 -> a;
      2 -> b;
      _ -> c

But it gets hairier (but not impossible) when you introduce several
variables in a case...


More information about the erlang-questions mailing list