defmacro

Discussion of Common Lisp

defmacro

Postby abetul » Fri Sep 25, 2009 11:45 am

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
abetul
 

Re: defmacro

Postby nuntius » Mon Sep 28, 2009 6:33 pm

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.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: defmacro

Postby janders468 » Thu Oct 01, 2009 8:28 am

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.).
janders468
 
Posts: 16
Joined: Fri Oct 17, 2008 12:27 pm

Re: defmacro

Postby Jasper » Fri Oct 02, 2009 12:49 pm

In CL, macro-function is actually setf-able, if you're feeling silly.
Jasper
 
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron