--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Bruce Tate | CTO | 512.772.4312
Innovation + Research. Made Simple
powered by Sentient Services
Remember that fn can be multi-headed:
iex> Enum.map 1..5, fn x when x>3 -> "big"; _ -> "small" end
["small", "small", "small", "big", "big"]
Enum.reduce list, 0, (x, y -> x + y)
Enum.reduce list, 0, (x, y -> x + y)
There is one syntax we could support and that is already valid today. You use (x -> y) in typespecs to define functions:Enum.reduce list, 0, (x, y -> x + y)
Just as a note, historically, "fn ... -> ... end" was added as a shortcut to "function do ... end":
function dox -> x + 1end
Became:
fn
x -> x + 1end
I.e. "fn" became a keyword that represents "function do". We no longer have "function do", but remember that:
case x doy -> zend
Translates to:
case x, do: (y -> z)
Now, answering your questions, the syntax above does support 0 arity functions:spawn_link (->IO.puts "Hello")What I dislike about it though is it interacts with optional parentheses in the language:# This worksspawn_link (-> IO.puts "HELLO")spawn_link((-> IO.puts "HELLO"))
# Invalid syntaxspawn_link(-> IO.puts "HELLO", :some_arg)spawn_link(:some_arg, -> IO.puts "HELLO")
# Invalid (because it is ambiguous) but could be made to workspawn_link(-> IO.puts "HELLO")
I also want to point out that I am going to frequently bounce ideas through this mailing list and they do not mean, by any chance, that they will be added to the language. The point is to simply get feedback or start a discussion about a particular topic.
That being said, is there already consensus about the anonymous functions calling syntax (keeping the f.(x) syntax, or changing to f(x), etc.)?