This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

defmacro

4 posts · 1937 views

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

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

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

In CL, macro-function is actually setf-able, if you're feeling silly.