Matching elements of records

Vlad Dumitrescu vlad_dumitrescu@REDACTED
Fri Oct 29 08:37:48 CEST 2004


From: "Richard A. O'Keefe" <ok@REDACTED>
>     To me it is simply inconsistent to bind X in the body of a function
>     by writing
> X = [Y|Ys]
>     and then to turn around and do the exact OPPOSITE in the head of
>     a function by writing
> [Y|Ys] = X

Hi,

Without trying to pretend I know more than you, Richard, there is one thing that
I'd like to point out (which might or might not invalidate your point).

As I see it, the alternatives are these:

a) f(X = [Y|Ys]) -> ...

b) f([Y|Ys] = X) -> ...

c) f(X) ->
    [Y|Ys] = X, ...

d) f([Y|Ys]) ->
    X = [Y|Ys], ...


Alternatives a and d are consistent with each other, and in line with your
preferences.
Alternatives b and c are consistent with each other, and in line with Robert's
preferences.

However, alternative d seems a little strange and there's something unnatural
about it. The match follows the "heavy constituent comes later" rule, but the
function as a whole doesn't (argument name should have come first). And I think
when it comes to readability, the function as a whole is more important to
follow the rule.

That said, I too would like to have a separate operator for record field
definition.

regards,
Vlad



More information about the erlang-questions mailing list