Learning Elixir, frst impressions ( plz don't kill me ! )

There is no requirement to bind an anonymous function to a name before it can be invoked:


  def partially_apply_me(left_addend) do
    fn (right_addend) -> left_addend + right_addend end
  end

  IO.puts partially_apply_me(3).(5)

Or simply:

iex(4)> (fn (x) -> IO.puts(x) end).("foo")  
foo
:ok

But in these examples, as well as the one above where the function is bound to a variable the .() syntax is consistently applied to indicate that you are applying parameters to an anonymous function.

It might be that in the partial application case you could unambiguously drop the dot, but then that would then be an inconsistency in the syntax of calling anonymous functions.

1 Like