[erlang-questions] Function Declaration Syntax

Daniel Dormont <>
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)
functions :)

dan

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
> end.
>
> 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
>    end
>
> 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
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110516/6cce586c/attachment.html>


More information about the erlang-questions mailing list