elixir - what's up with this anonymous function syntax? -


Just start on my nectar trip, reading it in a book:

"& amp; The operator converts the expression that is included in a function. "

OK, I think I found that. ..

  isx (70)> F = & amp; (& Amp; 1 * and 2) # function & lt; 12.80484245 in: erl_eval.expr / 5 & gt; IEX (72) & gt; F (2,3) 6  

OK, the ampersand is a cloak for an anonymous function and it's logic but then why does not this next call work ?!

  iex (73)> & Amp; (& Amp; 1 * and 2) () # Function & lt; 12.80484245 in: erl_eval.expr / 5 & gt;  

... and I can do it forever:

  iex (76) & gt; & Amp; (& Amp; 1 * and 2) (). (). () # Function & lt; 12.80484245 in: erl_eval.expr / 5 & gt;  

What's going on here?

If you do an anonymous operation with brackets, this will work:

  Iex (1) & gt; (& Amp; 1 & 2)) () ** (BadArityError) & amp ;: erlang * 2 with 2 arity with a debate called  

The error is expected, because we are calling 2 eriti fun with zero arguments. If we pass it to two numbers, then we should multiply them together:

  iex (2) & gt; (& Amp; (& amp; 1 * and 2)) (2,3) 6  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -