Matching elements of records

Richard A. O'Keefe ok@REDACTED
Thu Oct 28 05:35:14 CEST 2004


I pointed out that the other funcitonal programming languages
I use only support the <as-variable> before <as-pattern> usage,
not the reversed usage.

David Hopwood <david.nospam.hopwood@REDACTED> wrote:
	
	The general case (supported by several languages including Oz
	and E, for example) is
	
I know perfectly well what the general case is.  The only language you
needed to mention here was Erlang.

	and so it makes no sense to disallow the "reversed" special case.
	
This is a non-sequitur.  The fact that some languages (including Erlang)
allow the reversed case is no reason why it *has* to be used, and saying
that avoiding a less readable usage "makes no sense" is, um, odd.  You
can reasonably say that you don't _agree_, but not that it makes no sense.

There's a fairly basic rule of English syntax.  It's not universal, but
it's fairly common in natural languages.  It's a (strong) pragmatic
tendency, not a hard law.  It's this:  "heavy" constituents go last.
It presumably has something to do with human memory limitations.
We find
    This is the dog that bit the rat that ate the malt in the house that
    Jack built
with branching on the right much easier to read than the left branching
alternative equivalent.

variable on the left automatically ensures that the "heavy" component,
the branching component, is on the right.

Somehow
    f(X = {a,b,c,d})
looks right, while
    f({a,b,c,d} = X)
looks as though "=" was a misprint for ",".

Until we have some experimental evidence about readability in Erlang,
we'll have to put this down as a matter of taste, but there _is_ the
evidence from natural language that variable on the left might be
more readable, so it hardly makes "no sense" to recommend what we have
reason to believe is more readable.




More information about the erlang-questions mailing list