Matching elements of records

Bjorn Gustavsson bjorn@REDACTED
Mon Nov 1 09:39:44 CET 2004

IMHO, it is still a matter of taste. (For the record, I prefer
the variable to the right.)

"Richard A. O'Keefe" <ok@REDACTED> writes:

> (A) Consistency with other functional programming languages, ...
> ML, Haskell

The best of the arguments.

> (B) The linguistic argument.  In fact this has two versions.  One is
>     "heavy constituent comes later".  The other is "most salient    
>     constituent comes first".  To me, when you have an as-pattern,
>     the most salient part is the name.  That's the "topic"; the
>     restrictive pattern is the "comment".

In a head, I see the matching as the most important thing, and binding
to a variable as an afterthought just because I'll need the entire term
later (perhaps much later) in the body.

>     To me it is simply inconsistent to bind X in the body of a function
>     by writing
> 	X = [Y|Ys]	

This is how you build a new list in a body.

>     and then to turn around and do the exact OPPOSITE in the head of
>     a function by writing
> 	[Y|Ys] = X

That's the way you do matching in a body.

Why would you want a matching in head look like it was an assignment

        X = [Y|Ys]

in a body?

I prefer 


which is can be seen to be a matching regardless of context.

Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list