News for hackers. Stuff that matters.
Re:Elixir in Depth – Reading and personal notes by josevalim on Thursday August 17, 2017 @05:02PM (#15040977)
> Macros can't take a variable number of arguments, which leads to the proliferation of Special Forms which could perfectly be macros if it weren't for this limitation.

This is not true.

We have only two variadic special forms: "for" and "with".

"for" needs to be implemented as a special form as it emits some optimizations that are only available at the Core Erlang level.

"with" needs to be implemented as a special form as it has different lexical properties than a bunch of nested cases.

None of those could be implemented with macros.

Regarding whitespace sensitiveness, most languages have subtle issues, to varying degrees but especially if you have optional line terminators. Although it is true one or two extra cases appear in Elixir due to optional parentheses.

Re:Elixir in Depth – Reading and personal notes by randomstudent on Friday August 18, 2017 @08:07AM (#15045391)
> "for" needs to be implemented as a special form as it emits some optimizations that are only available at the Core Erlang level.

That's interesting. I wonder if a future Elixir version could have a way of defining macros which sould emit these optimizations. Is this a likely direction for future developments?

> "with" needs to be implemented as a special form as it has different lexical properties than a bunch of nested cases.

Could you expand on this a little? What are those different lexical properties?

Re:Elixir in Depth – Reading and personal notes by josevalim on Saturday August 19, 2017 @03:04AM (#15052105)
> That's interesting. I wonder if a future Elixir version could have a way of defining macros which sould emit these optimizations. Is this a likely direction for future developments?

To do so, we would need to compile to core, and that means tools like Cover and the Erlang debugger would no longer work with Elixir. It is unlikely we will go to this direction.

> Could you expand on this a little? What are those different lexical properties?

If you compile a "with" to a bunch of cases, a variable from the outer case would be available to both success and failure cases. Take this code:

    a = true
    with true <- a = false do
      a
    else
      _ -> a
    end
In Elixir it returns true because `a = false` has no impact on else. But if it compiled to a bunch of cases, we would get:

    a = true
    case a = false do
      true -> a
      _ -> a
    end
And that returns false.