These days, I challenge exercism.io to get used some languages. Especially, I use Erlang and Swift.
Then, I found some difference between Erlang and Elixir in aspect of syntax. So, I describe them as articles to remember them.
This time, I attached gist which is run function defined in variables.
Elixir run them with func.()
, but Erlang tun them with Func().
. We can give variables via func.(some_variables)
, Elixir, and Func(Some_variables).
, Erang.
iex> f = fn -> IO.puts("hello") end
#Function<20.54118792/0 in :erl_eval.expr/5>
iex> f.()
hello
:ok
iex> f = fn x -> IO.puts("hello #{x}") end
#Function<6.54118792/1 in :erl_eval.expr/5>
iex> f.("world")
hello world
:ok
> Fnc = fun() -> io:format("hello~n") end.
#Fun<erl_eval.20.54118792>
> Fnc().
hello
ok
> Fncx = fun(X) -> io:format("hello ~s~n", [X]) end.
#Fun<erl_eval.6.54118792>
> Fncx("world").
hello world
ok
These are like yield
.