chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: Stupid backquote/unquote question


From: Alaric Snell-Pym
Subject: Re: [Chicken-users] Re: Stupid backquote/unquote question
Date: Fri, 22 Feb 2008 10:55:29 +0000


On 21 Feb 2008, at 3:39 pm, Hans Nowak wrote:

(Which leads me to wonder, *are* there Lisps/Schemes that have
first-class macros?  Where you can, for example, pass a macro as an
argument to map, the way you can do with a function?)


There can be, in principle, but they wouldn't be very compilation-
friendly.

Take the metacircular evaluator out of SICP, and modify the semantics
of function such that, if the function is a function, evaluate all
its arguments and apply it to the result. If it's a macro, then do
not evaluate the arguments; just pass them directly to the underlying
function of the macro, then recursively evaluate the result in the
same environment...

However, doing this in a compiler would be a pain, since you cannot
in general tell if (a b c) is a function call or a macro reference.
So for every application you'd need to output code that, if it was a
macro, applied it to (b c), then called (eval ...) on the result, in
a specially constructed environment. Eg, you'd end up evaluation
anything that was made with macros anyway, unless you got really
clever with "metacompiling" macros, eg making them produce compiled
code rather than Scheme expressions. Which might be possible in some
situations.

However, you can make macros into "second class values", a term I use
to describe things which do behave much like first class objects,
*except* that they must be fully decidable at compile time.

Eg, we could allow:

(defmacro (foo ...) ...)
(defmacro (bar ...) ...)

(define baz (if #t foo bar))

(baz ...)

Or:

(define (wibble macro)
   (macro 1 2 3))

(wibble foo)

Since in both cases, we can tell that it's foo we're using, at
compile time, with a little bit of partial evaluation.

ABS

--
Alaric Snell-Pym
Work: http://www.snell-systems.co.uk/
Play: http://www.snell-pym.org.uk/alaric/
Blog: http://www.snell-pym.org.uk/?author=4






reply via email to

[Prev in Thread] Current Thread [Next in Thread]