The point I think he was trying to make was that Lisp's syntax is less restrictive, but that seemed to get confused by:
- mentioning the some people say it has no syntax (which it definitely does have)
- saying macros can create new syntax (which they can't in Lisp)
Elixir macros are approximately the same as Lisp macros (apart from not being able to take a variable number of arguments).
This is a straight port of that macro into Elixir:
defp kl_i([k, v | t]) do
quote do
[
{unquote(Macro.escape(k)), unquote v}
| unquote kl_i t
]
end
end
defp kl_i([]), do: quote do: []
defmacro kl(l), do: kl_i l
# usage
IO.inspect kl [a, 2 + 7, b, 6]
# => [{{:a, [line: 16], nil}, 9}, {{:b, [line: 16], nil}, 6}]
Note: Elixir's syntax does get in the way a bit here, the `a` and `b` are converted into nullary calls, you could use a different escaping function to fix this defp escape_key({v1, v2}), do: {escape_key(v1), escape_key(v2)}
defp escape_key({:{}, pos, els}) when is_list(pos), do: {:{}, pos, Enum.map(els, &escape_key/1)}
defp escape_key(els) when is_list(els), do: Enum.map(els, &escape_key/1)
defp escape_key({sym, pos, nil}) when is_list(pos), do: Macro.escape sym