[erlang-questions] Function Declaration Syntax
Mon May 16 06:02:27 CEST 2011
I'd like to add that neither Haskell nor Standard ML, both of which I used
long before I discovered Erlang, allow anonymous functions to have multiple
clauses. Discovering that feature in Erlang was a nice treat.
On the other hand, they do both allow nested named (and hence recursive)
On Sun, May 15, 2011 at 11:58 PM, Richard O'Keefe <> wrote:
> On 14/05/2011, at 3:01 AM, Attila Rajmund Nohl wrote:
> > The (usual) problem is that this is not consistent. You have to write
> > the function name for different function clauses, but must not write
> > the 'fun' for different clauses in anonymous functions. I would prefer
> > the 'fun' anu anonymous functions too.
> But that's because "fun" isn't the anonymous function's name.
> The name of the anonymous function *is* repeated in every clause.
> That name is the sequence of characters strictly between these
> brackets: .
> fun (........) -> .......
> ^ name
> ; (........) -> .......
> ^ exactly the same name again
> You may not *like* the name being invisible, especially because that
> makes it impossible to write recursive funs, but you can't really
> call it inconsistent (:-) (:-).
> An interesting alternative would be to allow
> fun F(N) when is_integer(N), N > 1 -> F(N-1) + F(N-2)
> ; F(1) -> 1
> ; F(0) -> 1
> and if the variable here were optional (either appearing in all
> clauses or disappearing in all clauses) it would be clear that the
> traditional form has a consistently repeated but invisible name.
> The thing that makes funs look ugly is people putting the semicolons
> in the wrong place...
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions