[erlang-questions] Simple Erlang Recommendation (last returned value)

Richard A. O'Keefe <>
Tue Jul 29 01:22:52 CEST 2008

On 28 Jul 2008, at 10:10 pm, Jesper Louis Andersen wrote:
> This is infected with Ocaml syntax style :)

OUCH!  That hurts!  OCaml has to be one of the ugliest
genuinely useful functional languages around!

> The SML way would be:
> let
>  val x = 1
>  val x = x + 1
> in
>  x + 1
> end

I knew I could do that.  That's how SML handles top level bindings,
for example.  There's a classic trap for young players there:

	- val x = 1;
	- fun f y = x + y;
	- f 2;
	val it = 3 : int
	- val x = 4; (* whoops, x was wrong, fix it *)
	- f 2;
	val it = 3 : int

The new binding for x *shadowed* the old one, it did not *replace it*.
So f still uses the old binding, and there's no way to fix it but to
redefine f as well.

Too much painful experience with this led me to the rule "NEVER
declare the same variable twice at the same level, even if you are
allowed to".  That's one of the reasons I don't want *X in Erlang.

More information about the erlang-questions mailing list