chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Implementing a macroexpand-all


From: Patrick Li
Subject: [Chicken-users] Implementing a macroexpand-all
Date: Fri, 11 Feb 2011 11:07:43 -0500

Hello everyone,

I'm trying to write a simple macroexpand-all function (a function to recursively macroexpand all subforms in a form until there are absolutely no macros left in the form), and realized that my naive implementation has a serious bug in it, namely that it doesn't keep track of local bindings within an expanded form.

Naive implementation:
(define (macroexpand-all _expression_)
  (let ((expanded (expand _expression_)))
    (if (pair? expanded)
        (map macroexpand-all expanded)
        expanded)))

I want the function to obey this property:
(eval some-_expression_) is *always* equivalent to (eval (macroexpand-all some-_expression_))

Is there an easy or existing way to do this? I have tried to write my own, but do not know which special forms actually introduce new bindings. 

eg. I thought everything reduces down to (lambda ( ... )) eventually. 
But calling (expand '(let ((x 1)) (display x))) still yields (let ((x 1)) (display x))

Thanks very much for your help!
  -Patrick

reply via email to

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