News for hackers. Stuff that matters.
Re:Learning Elixir: My side-project by CoderPuppy on Sunday July 09, 2017 @04:27PM (#14731512)
Yes, sorta.

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
Re:Learning Elixir: My side-project by eggy on Wednesday July 12, 2017 @12:56AM (#14750203)
I sort of get it. But this part he writes in the discussion seems to hold, no?

"What I mean here is that elixir has a predefined syntax. It has a number of predefined syntactic constructs, operators and function calls. And while I can with macros change the meaning of the constructs I cannot add new constructs or operators as the handling of macros is done after parsing. So if I want to add something completely new it ends up syntactically being a function call. Now elixir has many ways of disguising function calls at the end of the day they are syntactically still function calls. For example parentheses around arguments are optional, there is special syntax for property lists where the keys are all atoms, special syntax for using these property lists as function arguments, special handling of do ... end when it is a function argument, etc. Elixir's uniform abstract syntax makes it easier to work with these but I am still limited by only having the existing syntax."