Let me guys propose a solution.
The elixir interpreter fails to evaluate the following expression (good news):
def(sayhi("world", do: "Hello" <> " world!"))
it does not have a block do expression, so it is what we would expect: an error for a function without do
.
But (if arguments without parenthesis implemented) so would the following expression be an error, because it does not have a do
block.
def sayhi_with_kwarg "world", do: "Hello" <> " world!"
It contains two values world
and the keyword argument. Yet! The interpreter could understand that what is trying to be expressed is a do
block and not a value, because otherwise it would make little sense, if any, define a function without a do
block.
And since a function definition must expect an atom for do
let the interpreter identify such keyword list that contains only this expected keyword list definition for the function.
With this in mind,
def sayhi_with_kwarg "world", do: "Hello" <> " world!"
would turn into
def(sayhi("world"), do: "Hello" <> " world!")
Fine. And since we expect this from the interpreter, the following would be totally fine as well:
def sayhi_with_kwarg "world", do: "Hello" <> " world!", do: "Hello" <> " world!"
leaving the last keyword-list expression as the do
block of the function.
Effectively resulting in (as an example):
def sayhi_with_kwarg "world", do: "Hello" <> " world!" do
"Hello" <> " world!"
end
Am I missing something? 