[erlang-questions] clarify: variable as function name

Emad El-Haraty elharaty@REDACTED
Mon Dec 10 19:46:23 CET 2007


you need to specify the module:


f() -> ok.
g() -> F=f, ?MODULE:F().

h(X) -> M=erlang, F=is_integer, M:F(X).

the function h/1 works just fine since the module is specified,
the function g/0 works when a module is specified

On Dec 10, 2007 2:24 AM, 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
>



More information about the erlang-questions mailing list