Emulator syntax question

Vlad Dumitrescu XX (LN/EAB) vlad.xx.dumitrescu@REDACTED
Wed Apr 19 09:26:50 CEST 2006


Hello, and welcome!

The short answer is that in the shell you can only define anonymous
functions, like you have discovered.

Defining one with several clauses is written like this

    Xg = fun(1) -> hello; (2) -> throw({myerror, abc}) end.

It may be easier to use modules and files instead of fighting the shell
(where some things are different than usual). Emacs with the Erlang mode
is useful, you can have the file and the shell accessible directly.

Hope this helps.
Regards,
Vlad
 

> -----Original Message-----
> From: owner-erlang-questions@REDACTED 
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of Raoul Duke

> The basic problem is that I'm trying to enter a function 
> definition with the syntax one would use in a module file, 
> and it doesn't work in the emulator. I can't use tabs to 
> indent things like I see in the tutorials (tab shows me a 
> list of commands), so I try to do them on a single line using 
> ";" and "." and maybe "end".
> 
> I can get the function to work if I bind an anonymous one to 
> a variable, but then I can't figure out how to do more than 
> one function clause e.g. like what you'd do for factorial. 
> "Xg = fun(1) -> 'hello'
> end." works but "Xg = fun(1) -> 'hello'; fun(2) -> throw({myerror,
> abc}) end." nets me "** 1: syntax error before: 'fun' **"



More information about the erlang-questions mailing list