[erlang-questions] DRY principle and the syntax inconsistency in fun vs. vanilla functions
Mon May 23 05:18:35 CEST 2011
On 20/05/2011, at 1:43 AM, Michael Turner wrote:
> The other parts of your argument relate to a problem shared with *every* language whose syntax has ever changed -- and that's all of them, except some dead ones perhaps. Should you try to be backward compatible with every release of every implementation of every language? Then languages wouldn't ever evolve. Is that such a good state of affairs?
> As for the befuddled newbie who runs smack into code not described in any book,
Once again, it *is* described in the reference manual.
That *has* to count as one of the relevant books.
> supposedly becoming "*incredibly* confused ", that's pretty much a non-issue in this case
Only so long as no code in the proposed style exists!
> the simple reason that, for its intended purpose, the syntax I propose is transparently obvious,
No, it is *NOT* transparently obvious.
> at least if indented the way I propose (but that people here keep ignoring for some reason.)
I don't think anyone has been ignoring it.
Other people have criticised your proposed indentation,
and I for one have proposed an alternative which is
marginally less hostile to readers.
I have seen this kind of syntax before in extensions to Scheme.
It was NOT transparently obvious there,
and it is not transparently here.
There is, quite frankly, no such thing as "transparently obvious here.
It's like what Ponder Stibbons says to the Archchancellor in "Hogfather"
about the thinking engine, Hex:
it's perfectly intuitive.
You just have to spend six months learning it first.
As it happens, I've written and tried to read enough code in this style
to say that the "clueless" (as in, "it does not offer the reader any
clue other than indentation") style *never* became "transparently obvious
Right now, there is a way to get very very nearly the style you want,
with no language change whatever. Write
foobar(_1, _2, _3) ->
fun (....) -> ...;
(....) -> ...;
(....) -> ...
end(_1, _2, _3).
Done this way, the syntax for normal functions would not merely be
_like_, it would actually _include_ the syntax for "funs" precisely.
I note that ML also admits this possibility. Instead of
fun f (_:_) = ...
| f () = ...
you *can* write
val f = fn (_:_) -> ...
|  -> ...
with no repeated name.
Absolutely NO ML code that I've ever seen does it that way.
Given absolute freedom to write functions the Erlang way or
your way, ML programmers do not choose your way.
I wonder why?
More information about the erlang-questions