Emulator syntax question

Matthias Lang <>
Wed Apr 19 09:30:27 CEST 2006


Raoul Duke writes:

 > I'm attempting to learn Erlang, at least a little, and am running into
 > issues right off the bat with the 'BEAM' emulator - presumably an
 > impedence mismatch between my expectations from other interactive
 > shells and Erlang's actual approach.

Yep, that's it. You're expecting the shell to interpret Erlang
programs, whereas it only interprets Erlang expressions. So while
things like 

  1> 3 + 9.
  12
  2> lists:reverse("ekuD luoaR").
  "Raoul Duke"

work, you can't define a normal function in the shell.

As you figured out, you can define anonymous functions in the shell,
but I don't think it's a pleasant way of playing around with
Erlang. And you have to resort to tricks to get recursion.

Bottom line: the normal way to write Erlang code is to put it in a
file and compile the file.

 > "Xg = fun(1) -> 'hello'; fun(2) -> throw({myerror, abc}) end." 
 > nets me "** 1: syntax error before: 'fun' **"

Try deleting the second occurrance of "fun", i.e.

3> Xg = fun(1) -> 'hello'; (2) -> throw({myerror,abc}) end.       
#Fun<erl_eval.6.10732646>

Matthias



More information about the erlang-questions mailing list