chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] numbers and compiler macros


From: felix winkelmann
Subject: Re: [Chicken-users] numbers and compiler macros
Date: Tue, 19 Jun 2007 15:14:54 +0200

On 6/19/07, Alex Shinn <address@hidden> wrote:
On 6/18/07, felix winkelmann <address@hidden> wrote:
>
> Should there be bugs, or if the code generated is too big, compiler macros
> (which implement this feature) can be disabled via the
> "-disable-compiler-macros"
> option to chicken/csc.

Nice!  I've been wanting compiler macros for a while :)

Among other things, they can be used to implement
another feature I've wanted, first-class inlined procedures:

(define-compiler-macro (define-inline* params . body)
  (let ((body `(begin ,@body)))
    `(begin
       (define ,params ,body)
       (define-compiler-macro ,params
         `,,body))))

(define-inline* (foo x) ...)

This way FOO is inlined when applied directly, but is still
available as a normal procedure for first class usages
(e.g. with APPLY) and at runtime.

Careful: compiler macros are run *after* any highlevel macro-expanders
have processed the code, so they should expand into code that does not
use macros (this doesn't come up with low-level macros, as they are
expanded as a toplevel expression is "canonicalized" - first macros are
expanded, then compiler macros). But all highlevel macro systems
(syntax-case, syntactic-closures, alexpander, rex) must expand toplevel
expressions completely and will not run after a compiler macro has been
expanded.
So compiler macros are not for general use (and so they are undocumented),
but are sometimes the only way of getting something to work.


cheers,
felix




reply via email to

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