Consistent function calls

37 views
Skip to first unread message

Matt R

unread,
Jul 6, 2016, 6:54:29 PM7/6/16
to elixir-lang-core
Given this code:

defmodule
Foo do
 
def bar(i), do: i * 2
end

anon
= fn (i) -> i * 2 end

import Foo

Foo.bar(3) # 6
Foo.bar 3 # 6
bar(3) # 6
bar
3 # 6
(&bar/1).(3) # 6
anon
.(3) # 6

3 |> Foo.bar() # 6
3 |> Foo.bar # 6
3 |> bar() # 6
3 |> bar # 6
3 |> (&bar/1).() # 6
3 |> anon.() # 6

Both are functions, one anonymous one defined in a module. Yet calling them is very different, starting with the dot before the parenthesis for the anonymous function. Also, you can't call it without parenthesis, unlike named functions

Is there a reason for this distinction?

If not, I propose to remove that distinction and have the call be the same. 

Eric Meadows-Jönsson

unread,
Jul 6, 2016, 10:10:16 PM7/6/16
to elixir-l...@googlegroups.com
This has been discussed many times in the past. You can find discussions on the mailing lists and other places by searching.


Here is a discussion about changing the behaviour (although old) which might give some additional insight: https://groups.google.com/forum/#!msg/elixir-lang-core/_kEBXO0NRDY/fmdkDvCHLsEJ

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d24b8458-1510-4bbb-a284-868e91a3b758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson
Reply all
Reply to author
Forward
0 new messages