[erlang-questions] Function Declaration Syntax

Richard O'Keefe <>
Mon May 16 05:06:34 CEST 2011

On 13/05/2011, at 9:43 PM, Justus wrote:

> Hi all,
> I come to a question on function declaration syntax: why does function
> name appear in each clause?
> Name(Pattern11,...,Pattern1N) [when GuardSeq1] ->
>    Body1;
> ...;
> Name(PatternK1,...,PatternKN) [when GuardSeqK] ->
>    BodyK.

Why not?
That's how you do do it in mathematics when defining a recurrence.
That's how it's done in Haskell.
That's how it's done in SML.
That's how it's done in every functional language I know that _has_
multiple clauses (so, not in Lisp).
> It does not provide any information, except that one might make silly mistakes.

Which do you suppose human beings rely on, when reading the code,
to tell whether clauses belong together?

 - the function name at the beginning of the line where they can see it
 - a distinction between "." and ";" at differently placed ends of lines?

> If omitting it, a new problem is how to indent clauses properly and
> beautifully.
> Name(Pattern11,...,Pattern1N) [when GuardSeq1] ->
>    Body1;
>    (PatternK1,...,PatternKN) [when GuardSeqK] ->
>    BodyK.

Don't.  Use 'case' instead.

For what it's worth, I write

	fun (....) when ... ->
	  ; (....) when ... ->

If you don't have a name to make the alignment obvious, you desperately
need the semicolon out the front.

More information about the erlang-questions mailing list