[erlang-questions] clarify: variable as function name

Anthony Kong anthony.hw.kong@REDACTED
Mon Dec 10 12:21:59 CET 2007


The proper syntax should be:

  g() -> F=fun f/0, F().

It is because if you simply put 'f' there, it is considered an atom, not a
function. Hence the 'badfun'.

Cheers, Anthony

On Dec 10, 2007 9:24 PM, 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
>



-- 
/*--*/
Experience is simply the name we give our mistakes.
---- Oscar Wilde
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071210/e06ca704/attachment.htm>


More information about the erlang-questions mailing list