Elixir macros vs Clojure macros

775 views
Skip to first unread message

ma...@aravindh.io

unread,
Oct 4, 2014, 2:56:54 PM10/4/14
to elixir-l...@googlegroups.com
Hi All, I am new to elixir and I am seriously excited about its features. I worked a bit in clojure and was excited about macros but was not dedicated enough to overcome the initial hinderance of clojure syntax. When I saw macros in elixir that too in a super simple form, I was excited. I know that we are transforming normal expressions in tuples during the compilation time. But can some one compare the power of lisp macros vs elixir macros. In lisp we directly code in the ast. We dont do so in elixir. Our compiler manipulates the ast which is in a tuple form. Is there anything that a lisp's macro can do that elixir's macro cant? Vice versa?


Thanks
Aravindh.S

Patrick Gombert

unread,
Oct 4, 2014, 3:15:22 PM10/4/14
to elixir-l...@googlegroups.com

Here's a blog I wrote on the subject.

http://blog.8thlight.com/patrick-gombert/2013/11/26/lispy-elixir.html

The two macro systems are really similar.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ma...@aravindh.io

unread,
Oct 4, 2014, 11:48:47 PM10/4/14
to elixir-l...@googlegroups.com
Thanks Patrick. That helps.

gvim

unread,
Oct 5, 2014, 9:18:28 AM10/5/14
to elixir-l...@googlegroups.com
It's worth bearing in mind that Clojure's macros aren't quite as
powerful as Common Lisp's where the reader itself can be manipulated by
macros. LFE (Lisp Flavoured Erlang) and Joxa are Lisps on the Erlang VM
so may offer a better comparison.

gvim

Robert Virding

unread,
Oct 6, 2014, 12:12:43 PM10/6/14
to elixir-l...@googlegroups.com
Lisp macros have a major benefit in that lisps are truly homoiconic so it is much easier to construct the resultant syntactic form. Also they allow you to create new syntax which elixir does not.

Robert

José Valim

unread,
Oct 6, 2014, 1:07:18 PM10/6/14
to elixir-l...@googlegroups.com
I will nitpick slightly. :)

Lisp macros have a major benefit in that lisps are truly homoiconic so it is much easier to construct the resultant syntactic form. Also they allow you to create new syntax which elixir does not.

I would say creating syntax forms in Elixir is about as easy as in Lisps. Because at the end of the day you just use quote and unquote. The difference is that in Elixir you need to type "quote" and "unquote" but that was a design decision for clarity, not a syntax limitation.

What is definitely easier in Lisps is traversing and understanding because the syntax tree is then just a list and not a mixture of tuples and lists. In Lisp, what you see (the code) is what you get (the tree).

> Also they allow you to create new syntax which elixir does not.

This is misleading because you still need to abide to the Lisp syntax. You can't drop or repurpose the parentheses, you can't make it space sensitive. You are still limited to the syntax defined by the tokenizer and the parser. Of course some languages restrict more and in different ways than others.

gvim

unread,
Oct 6, 2014, 1:26:46 PM10/6/14
to elixir-l...@googlegroups.com
On 06/10/2014 18:06, José Valim wrote:
> I will nitpick slightly. :)
>
> Lisp macros have a major benefit in that lisps are truly homoiconic
> so it is much easier to construct the resultant syntactic form. Also
> they allow you to create new syntax which elixir does not.
>
>
> I would say creating syntax forms in Elixir is about as easy as in
> Lisps. Because at the end of the day you just use quote and unquote. The
> difference is that in Elixir you need to type "quote" and "unquote" but
> that was a design decision for clarity, not a syntax limitation.
>
> What is definitely easier in Lisps is traversing and understanding
> because the syntax tree is then just a list and not a mixture of tuples
> and lists. In Lisp, what you see (the code) is what you get (the tree).
>
>> Also they allow you to create new syntax which elixir does not.
>
> This is misleading because you still need to abide to the Lisp syntax
> <http://en.wikipedia.org/wiki/Syntax_(programming_languages)#Example:_Lisp>.
> You can't drop or repurpose the parentheses, you can't make it space
> sensitive. You are still limited to the syntax defined by the tokenizer
> and the parser. Of course some languages restrict more and in different
> ways than others.
>

I'm no language expert but my impression is that Elixir's macros are
similar to Python's Hylang (http://hylang.org/) where you're
manipulating an intermediate form - the AST - whereas with Lisp it's
more direct.

gvim
Reply all
Reply to author
Forward
0 new messages