[racket] Macro Problem
Hello
I am having a problem with the following macro:
(define-syntax lambda-r
(syntax-rules ()
((_ args exp ...)
(lambda args
(call-with-current-continuation
(lambda (return)
exp ... ))))))
it's meant to define a lambda-r form, which wraps a lambda in call/cc,
so I can use a "return-like" operator.
The following is an example of using lambda-r:
(define test-return
(lambda-r ()
(let ((input (read)))
(if (number? input)
(if (> input 0)
(begin
(display "positive")
(return input)) ;; if
input is > 0 this should escape out of the procedure
(display "negative or zero"))
(display "not a number"))
(display "no return") ;; if input
is > 0 this shouldn't get displayed
)))
I get the following error when I run the previous example (and enter a
positive integer):
=> reference to undefined identifier: return
The puzzling thing is that if I run the macro expansion (as shown by the
Macro Stepper), it works !
Here is the macro expansion:
(define test-return
(lambda ()
(call-with-current-continuation
(lambda (return)
(let ((input (read)))
(if (number? input)
(if (> input 0)
(begin (display "positive") (return input))
(display "negative or zero"))
(display "not a number"))
(display "no return"))))))
What I am missing ?
Thanks
M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100709/b148f60f/attachment.html>