[plt-scheme] a simple macro redux

From: michael rice (nowgate at yahoo.com)
Date: Tue Nov 21 22:19:11 EST 2006

Let's forget about "syntax" for a minute. Here is a
regular non-hygienic macro that works fine in Common
Lisp but bombs in Scheme:

How would one write the macro mac in Scheme?

(defun fun (n) (cond ((zerop n) nil) (t (cons n (fun
(- n 1))))))

(defmacro mac (n) `(+ ,@(fun n)))

(fun 6) => (6 5 4 3 2 1)
(mac 6) => 21

==========================================

(require (lib "defmacro.ss"))

(define fun
  (lambda (n)
    (cond ((zero? n) '())
          (else (cons n (fun (- n 1)))))))

(define-macro (mac . n) `(+ ,@(fun n)))

> (fun 6)
(6 5 4 3 2 1)
> (mac 6)
. reference to undefined identifier: fun
>

What up?

Michael 



 
____________________________________________________________________________________
Sponsored Link

Rates near 39yr lows. $420,000 Loan for $1399/mo. 
Calcuate new payment. www.LowerMyBills.com/lre



Posted on the users mailing list.