[r6rs-discuss] [Formal] Implementing Common Lisp's defmacro is not straigtforward.

From: Eli Barzilay <eli>
Date: Thu Sep 21 11:54:31 2006

On Sep 17, Pascal Costanza wrote:

> Full description of the issue:
>
> Section 17.6, page 113, last paragraph, states that "Using lisp-
> transformer, defining a basic version of Common Lisp's defmacro is a
> straightforward exercise."
>
> This is misleading. [...]

I don't think so. I read "basic version" as the basic version that is
commonly found in some Schemes -- no destructuring and no
environments. Basically this (from an old post):

  (define macros '())
  
  (define nothing (list "nothing"))
  
  (define (preprocess-expr expr)
    (cond
     ((not (pair? expr)) expr)
     ((eq? 'defmacro (car expr))
      (set! macros
            (cons (cons (cadr expr)
                        (eval `(lambda ,_at_(cddr expr))))
                  macros))
      nothing)
     ((assq (car expr) macros) =>
      (lambda (m) (preprocess-expr (apply (cdr m) (cdr expr)))))
     (else (cons (preprocess-expr (car expr))
                 (preprocess-expr (cdr expr))))))
  
  (define (preprocess)
    (let loop ((expr (read)))
      (if (not (eof-object? expr))
        (let ((expr (preprocess-expr expr)))
          (if (not (eq? nothing expr))
            (begin (write expr) (newline)))
          (loop (read))))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
Received on Thu Sep 21 2006 - 11:54:25 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC