A basic question

Mikael Pettersson mikpelinux@REDACTED
Sun Mar 1 10:37:05 CET 2020


On Sun, Mar 1, 2020 at 10:28 AM salil GK <gksalil@REDACTED> wrote:
> forloop(X) ->
>   Fn = myfunc(Val) ->
>       io:fwrite("From myfunc ~w" , [Val]) end,
>   for(X, Fn).
>
> <<<<<
>
> basically I am trying to make a for loop with a call back function.
> I am getting the following error while compiling
> hw.erl:23: syntax error before: '->'
> line 23 is
>   Fn = myfunc(Val) ->

The syntax is "Fn = fun(Val) -> ... end", where "fun" and "end" are
keywords, not identifiers.
See https://erlang.org/doc/reference_manual/expressions.html#fun-expressions


More information about the erlang-questions mailing list