[erlang-questions] clarify: variable as function name

Robert Virding rvirding@REDACTED
Mon Dec 10 23:04:31 CET 2007


I think the main problem is that the documentation is a little unclear as to
what should syntactically be an atom, or if not an atom what it can/should
evaluate to. Unfortunately it is not consistent.

So with

    ExprF(Exp1, ... , ExprN)

ExprF should (syntactically) be an atom, or it should evaluate to a fun.
That's it, no other options.

With

    ExprM:ExprF(Expr1,...,ExprN)

ExprM and ExprF should (syntactically) be atoms or evaluate to atoms. Again
that's it.

Originally it was actually a little more consistent as only the atom forms
were allowed. So it was only foo(...) and foo:bar(...). For the case where
they weren't atoms you had to use apply/2/3. You can view the forms when not
atoms as syntactic sugar for apply (which they actually are):

ExprF(Expr1 ... ExprN)   ==> apply(ExprF, [Expr1 ... ExprN])
ExprM:ExprF(Expr1 ... ExprN)   ==> apply(ExprM, ExprF, [Expr1 ... ExprN])

(but optimised so the argument lists are never built) Then it is consistent.

Robert

P.S. Forget the {ExprM,ExprF} form for apply/2, it was a pseudo fun hack
from before funs.


On 10/12/2007, Lovei Laszlo <lovei@REDACTED> wrote:
>
> Hi all!
>
> A quote from the reference manual:
> http://www.erlang.org/doc/reference_manual/expressions.html#6.6
>
>    6.6 Function Calls
>
>    ExprF(Expr1,...,ExprN)
>    ExprM:ExprF(Expr1,...,ExprN)
>
>    ExprM should evaluate to a module name and ExprF to a function name
>    or a fun.
>    [...]
>    The module name can be omitted, if ExprF evaluates to the name of a
>    local function, an imported function, or an auto-imported BIF.
>
> This means that the following code is valid (F evaluates to a local
> function name):
>
>    f() -> ok.
>    g() -> F=f, F().
>
> In practice, this aborts with the reason badfun. The question is, which
> one is considered good: the manual, or the implementation?
>
>
> Thanks!
> Laszlo
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071210/2d098bb4/attachment.htm>


More information about the erlang-questions mailing list