3 ms·
> I think maybe is a clearer name for what the statement is doing and the lack of the 'do' block It's because basically everything in Elixir is a macro :), and
by troupo 3y ago
> I think maybe is a clearer name for what the statement is doing and the lack of the 'do' block
It's because basically everything in Elixir is a macro :), and the do block is an argument/parameter to that macro:
maybe x do
...
end
# is really
maybe x, do: ...
# which ends up being a macro call with a named parameter
maybe(x, do: ...)
Same goes for many (all?) other things in Elixir:
if x do
...
end
# is really
if x, do: ...
# which ends up being a macro call with a named parameter
if(x, do: ...)
And so on.
But it took me a very long to come to grips with this, too :)
- square_usual 3y agoI think GP is talking more about the fact that you can have a do block, not about what it is.
- Miner49er 3y agoYeah exactly, in Erlang the 'do' portion would just go in the same code block as the conditionals.