Calling an anonymus function without appending () ?

31 views
Skip to first unread message

bengt e

unread,
Jul 5, 2015, 1:47:32 AM7/5/15
to elixir-l...@googlegroups.com
Greetings,

Beginner question (still doing the getting started). Can I call an anonymus function (in a variable) without appending ()?

Given
iex(1)> f = fn () -> 1 end
#Function<20.90072148/0 in :erl_eval.expr/5>

Is there a way to call #Function<20.90072148/0 that does not involve () as shown below

iex(3)> f  .  ()
1


Previously in this group I have been shown that defining functions sometimes needs (), so I am always adding them when defining.
Are () also needed sometimes when calling?


bengt

José Valim

unread,
Jul 5, 2015, 5:59:34 AM7/5/15
to elixir-l...@googlegroups.com
No, it is not possible.

Previously in this group I have been shown that defining functions sometimes needs (), so I am always adding them when defining.

Well, it is not that they are required. The issue is that skipping them is ambiguous and would need to solve the ambiguity. Adding the parens are one way to solve it.

The most straight-forward thing to do when getting started, and the one we follow in our docs, is to always us parenthesis.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/b37a490a-3a6a-4661-8522-113c7506789a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages