[erlang-questions] Orthogonality and Principle of least surprise Was: chained functions
Thu Feb 2 05:46:01 CET 2012
On 1/02/2012, at 11:11 PM, Jakob Praher wrote:
> I am just wondering what the benefits of using "fun module:fun/0" are.
(1) It is unambiguous.
There is no remaining doubt about *which* function it refers to.
In contrast, module:fun refers to a potentially enormously large
family of functions (except, of course, that it doesn't, because
that family does not actually _exist_ as a concept in Erlang
This is a HUGE benefit for people.
(2) Because it is unambiguous, it is useful in cross-referencing.
(3) Similarly, it's much more use to a type checker.
> It is also just a designator (a reference) and has to be evaluated at runtime to get the address of the current function loaded.
Eh? How is that different from mention of a remote function?
In a call like module:func(Foo, Bar), where we know exactly what function we want and
what we want to do with it (call it!), we still have to figure out at run time what
the address is.
> I can think that "fun module:fun/0" is used to be more familiar with anonymous functions.
The actual syntactic form really isn't important. Having written an Erlang grammar from
scratch, I was really glad to have the 'fun' keyword to warn me what was coming next.
Disambiguating this occurrence of '/' from '/' meaning numeric division is helpful.
> According to parse_erl.yrl atom:atom is an expression (matched by expr_800), right?
It's a grammar hack; the kind of thing where the syntax over-generalises and the semantics
More information about the erlang-questions