[erlang-questions] Function Declaration Syntax

Justus mapandfold@REDACTED
Mon May 16 06:20:58 CEST 2011


On Mon, May 16, 2011 at 11:06 AM, Richard O'Keefe <ok@REDACTED> wrote:
>
> 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).

That's not good reasoning. Mathematica (it's as a FP language as Lisp)
also lists function names in each parameter pattern, but its semantics
is quite different from Erlang:

say[n_] := "n";
say[0] := "zero";

When calling say[0], the 2nd definition is used because it's more
*specific* than the 1st one. -- Different from Erlang.

The reason of the existence of function names here is mainly to help
us/ctags, etc not to get lost in code, although Joe said no deep
though is involved. That's OK, I like it.

>>
>> 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 ... ->
>            ...
>        end.
>
> If you don't have a name to make the alignment obvious, you desperately
> need the semicolon out the front.
>
>

Regarding eep-0028, I think putting ";" at the beginning of a line is
totally a bad idea, a big error in typesetting. There is already a
symbol for alignment, "(". How about this:

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

PS, after learn something about J, one might start to dislike anything
that seems to be redundant.

--
Best Regards,
Justus



More information about the erlang-questions mailing list