[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
more syntax silliness
From: |
Lynn Winebarger |
Subject: |
more syntax silliness |
Date: |
Mon, 19 Aug 2002 10:54:57 -0500 |
You can still get dynamic redefinition of syntax:
(define tmp
(let ((x 5))
(list
(lambda (y) (set! x y))
(lambda () x)
(lambda (exp)
(syntax-case exp ()
((_ z) (with-syntax ((x2 (datum->syntax-object (syntax _) x)))
(syntax '(z x2)))))))))
(define setx (car tmp))
(define getx (cadr tmp))
(define-syntax foo (caddr tmp))
> (foo bar)
(bar 8)
> (setx 3)
> (let-syntax ((baz (caddr tmp)))
(display (baz bar))
(newline)
(setx 'different)
(display (baz bar))
(newline)
(display (foo bar))
(newline))
(bar 3)
(bar 3)
(bar 3)
> (foo bar)
(bar different)
Now here's the fun part:
> (setx 2)
> (let-syntax ((baz (caddr tmp)))
(display (baz bar))
(newline)
(let-syntax ((foo (let ()
(setx 3)
(caddr tmp))))
(display (baz bar))
(newline)
(display (foo bar))
(newline))
(display (baz bar))
(newline))
(bar 2)
(bar 2)
(bar 3)
(bar 3)
> (setx 2)
> (let-syntax ((baz (caddr tmp)))
(display (baz bar))
(newline)
(let-syntax ((foo (let ()
(setx 3)
(caddr tmp))))
(display (foo bar))
(newline)
(display (baz bar))
(newline))
(display (baz bar))
(newline))
(bar 2)
(bar 3)
(bar 3)
(bar 3)
>
I don't know why the first and the second don't have the same output.
That is, it appears the inner foo's definition doesn't get evaluated until
that foo is actually used. This seems to me a mistake in Chez, but I could be
wrong.
Lynn
- more syntax silliness,
Lynn Winebarger <=