Why not `and` -> `andalso` and `or` -> `orelse`

I think that the code you showed is the code for a or b.

The Erlang compiler internally translates andalso and orelse to a case statement. Here is how the Erlang compiler internally translates an orelse:

case _a@1 of
  false -> _b@1;
  true -> true;
  __@1 -> erlang:error({badarg, __@1})
end

The only difference in the code is the code for generating the exception when the first operand is not a boolean. Elixir’s exception provides more information. I assume that’s why the Elixir compiler translates orelse itself instead of letting the Erlang compiler do it.

(Technical note: The Erlang compiler does this translation in the v3_core pass while translating to Core Erlang.)

10 Likes