[racket] metacircular interpreter: recursive macro expanding order ==> Re: metacircular interpreter: macro parser
Hi all -
I have now implemented the pattern matching/transforming algorithm of a
macro expander (no hygiene yet) for a single macro expansion call. The next
step is to figure out how to apply the macro expanders recursively "in
order".
For example, let's say we want to expand the following:
(or (and #t #t) #f)
Should it be expanded via the head position first (i.e. finish expanding or
before expanding and)
(or (and #t #t) #f)
=> (let ((g (and #t #t))) (if g g #f))
=> ((lambda (g) (if g g #f)) (and #t #t))
=> ((lambda (g) (if g g #f)) (let ((h #t)) (if h #t #f)))
=> ((lambda (g) (if g g #f)) ((lambda (h) (if h #t #t)) #t))
Or should the arguments be expanded before the head position expanding
again? (expanding or and and together):
(or (and #t #t) #f)
=> (let ((g (and #t #t))) (if g g #f))
=> (let ((g (let ((h #t)) (if h #t #f)))) (if g g #f))
=> ((lambda (g) (if g g #f)) (let ((h #t)) (if h #t #f)))
=> ((lambda (g) (if g g #f)) ((lambda (h) (if h #t #f)) #t))
Does (and should) it matter either way? Any inputs are appreciated.
Thanks,
yc
On Sun, Dec 5, 2010 at 11:21 AM, YC <yinso.chen at gmail.com> wrote:
>
>
> On Sun, Dec 5, 2010 at 10:47 AM, Jon Rafkind <rafkind at cs.utah.edu> wrote:
>
>>
>> Attached is a simple macro expander (but not hygienic) that follows the
>> algorithm laid out in the paper "Macro by Example" by Wand and others. Its
>> written in python but the code follows the paper reasonably close so maybe
>> you can understand it. The paper is on the acm digital library if you can
>> load it (but for some reason its not loading for me right now, so here is a
>> google search link to it).
>>
>>
>> http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBgQFjAA&url=http%3A%2F%2Fportal.acm.org%2Fcitation.cfm%3Fid%3D41632&ei=u9z7TPWCMY76sAO__MD3DQ&usg=AFQjCNGnasAUQsGpiVJik29wZRUwHBnz1w
>>
>>
> Thanks Jon for the example code and the links to paper. I don't have
> access to ACM, but the python code looks quite understandable, even though I
> am not too familiar with Python. I will study the code to see what I can
> glean from it.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101207/f4a25c48/attachment.html>