Alex Rivera | Logout

How far can LISP macros go?

Asked 2008-08-05T07:32:54.437
50

I have read a lot that LISP can redefine syntax on the fly, presumably with macros. I am curious how far does this actually go? Can you redefine the language structure so much that it borderline becomes a compiler for another language? For example, could you change the functional nature of LISP into a more object oriented syntax and semantics, maybe say having syntax closer to something like Ruby?

Especially, is it possible to get rid of the parenthesis hell using macros? I have learned enough (Emacs-)LISP to customize Emacs with my own micro-features, but I am very curious how far macros can go in customizing the language.

Edit
Report

2 Answers

11

Parenthesis hell? I see no more parenthesis in:

(function toto)

than in:

function(toto);

And in

(if tata (toto)
  (titi)
  (tutu))

no more than in:

if (tata)
  toto();
else
{
  titi();
  tutu();
}

I see less brackets and ';' though.

answered 2008-09-16T16:23:18.287
6

Yes, you can fundamentally change the syntax, and even escape "the parentheses hell". For that you will need to define a new reader syntax. Look into reader macros.

I do suspect however that to reach the level of Lisp expertise to program such macros you will need to immerse yourself in the language to such an extent that you will no longer consider parenthese "hell". I.e. by the time you know how to avoid them, you will have come to accept them as a good thing.

answered 2008-09-15T12:07:06.287

Your Answer