Page 1 of 1

defmacro

Posted: Fri Sep 25, 2009 11:45 am
by abetul
Hello everyone,

I am wondering how defmacro in common lisp is implemented with just defun. I ask this because I am trying to implement some metaprogramming into AutoLISP which does not have defmacro. Thanks

Albert

Re: defmacro

Posted: Mon Sep 28, 2009 6:33 pm
by nuntius
A common-lisp macro (automated code rewriting) is much different than an autolisp macro (stored user actions).

Macro expansion happens between parsing and compilation/evaluation. If you have a language without sufficient macros, you must find some way to leverage or sit between the existing parser and compiler. In many languages, that means writing your own parser, implementing your own macro expansion, and writing out the processed text for the target system to read directly.

Re: defmacro

Posted: Thu Oct 01, 2009 8:28 am
by janders468
The short answer is that common lisp does not define defmacro in terms of defun, it is acutally just the opposite, defun is a macro that can be implemented using defmacro.

In common lisp defmacro is also a macro, that utilizes the ability of common lisp to treat code as data and vice versa, but without this property built into the language you can't create new language constructs (such as defun, defmacro, defclass, defmethod etc.) I don't believe that autolisp supports macros (code as data etc.).

Re: defmacro

Posted: Fri Oct 02, 2009 12:49 pm
by Jasper
In CL, macro-function is actually setf-able, if you're feeling silly.