case some_fun(1) do
end
case some_fun() do
end
case some_fun do
end
We all know `do` binds to case. Therefore, if `fn` used `do`, the `do` would bind to the farthest call to: # this code
Enum.map list, fn do
end
# or this code
map list, fn do
end
would both bind `do` to `map`.Of course we could special case `fn do` but having `do` bind to different places based on `fn` would be extremely confusing.
Enum.map(list, fn do _ -> :ok end)
Is unambiguousHonestly I do appreciate not having to type two characters, but I'm currently onboarding a bunch of n00bs and they're very puzzled by this one inconsistency
Regardless of whether or not it's actively discouraged, it still must be supported since Elixir is so heavily bootstrapped. Since `defmodule`, `def`, etc are all just macros written in Elixir, there are no special rules around which functions/macros are allowed to be called without parens. There was some discussion about that on the forums a while ago (like requiring parens for functions and not for macros) and the answer is that that will never happen.
Take:
case value do
true -> "true"
false -> "false"
_ -> "uh..."
end
vs fn
true -> "true"
false -> "false"
_ -> "uh..."
end
`do` is simply syntactic sugar for a keyword list argument containing a `:do` key: if(true, [{:do, "hi there"}])
So it wouldn't make sense for `fn` to take a `do`. fn do
true -> "true"
false -> "false"
_ -> "uh..."
end[0] https://hexdocs.pm/elixir/1.14/Kernel.SpecialForms.html#fn/1
[1] https://hexdocs.pm/elixir/1.14/Kernel.SpecialForms.html#cond...