I can say<div><br></div><div>   fun (1)->2;</div><div>        (2)->1</div><div>   end</div><div><br></div><div>but, oddly, I can't define a named function in the analogous way, e.g.:</div><div><br></div><div>   factorial</div>
<div>     (1) -> 1;</div><div>     (N) -> N*factorial(N-1).</div><div><br></div><div>gives me a syntax error. I find the latter more readable than</div><div><br></div><div>   factorial(1) -> 1;</div><div>   factorial(2) -> N*fact(N-1).</div>
<div><br></div><div>It's also less to type and to read, which is consistent with the DRY principle ("Don't Repeat Yourself").  And it lends itself to reading a function definition as a set of cases. I think for Erlang newbies, it should therefore would be preferred: it helps underscore the pattern-matching style of Erlang function invocation.</div>
<div><br></div><div>It also looks a *little* bit more like the mathematical convention for defining these sorts of functions, where you have "f(x) = ", centered vertically to the left of a big left "{" that (left-)encloses the list of expression/parameter-condition pairs in a two-column format, e.g.,</div>
<div><br></div><div> <a href="http://cnx.org/content/m29517/latest/Picture%2047.png">http://cnx.org/content/m29517/latest/Picture%2047.png</a></div><div><br></div><div>So there's a (weak) argument from the Principle of Least Surprise here as well.</div>
<div><br></div><div>It seems to me that, if anything, this requires only a *simplification* of the Erlang parser. That leaves only one obvious objection: would any existing code break if Erlang syntax were altered to allow this?</div>
<div><br></div><div>-michael turner</div>