[gambit-list] Noob Problem with Macros?
William
william at soukoreff.com
Fri Aug 7 16:25:09 EDT 2020
Hello,
Sorry to bother everyone with what I’m sure is a silly-noob question…
I’m trying to learn about Scheme macros, and I’m having trouble getting
what I think is a relatively straight-forward macro to work in Gambit.
This formulation of my “while” macro works just fine:
(define-macro (while test . code)
`(let loop ()
(if ,test
(begin , at code (loop)) )))
~ ~ ~ ~ script output STARTS ~ ~ ~ ~
Script started on Fri Aug 7 15:45:49 2020
bash-3.2$ gsi
Gambit v4.9.3
> (define-macro (while test . code)
`(let loop ()
(if ,test
(begin , at code (loop)) )))
> (define i 0)
> (while (< i 10)
(println "i = " i)
(set! i (+ i 1)) )
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
> ,q
bash-3.2$
~ ~ ~ ~ script output ENDS ~ ~ ~ ~
Note that the gambit interpreter was started WITHOUT any command-line
arguments, and in particular without “-:s”.
My formulations of what I believe to be this same macro using SYNTAX-RULES
and SYNTAX-CASE, both fail regardless of whether I start the interpreter
with “-:s” or not:
Here’s my code:
(define-syntax while
(syntax-rules ()
((_ test code ...)
(let loop ()
(if test
(begin code ... (loop)) )))))
(define-syntax while
(lambda (x)
(syntax-case x ()
((_ test code ...)
(syntax
(let loop ()
(if test
(begin code ... (loop)) )))))))
And here is what happens when I try to run these:
~ ~ ~ ~ script output STARTS ~ ~ ~ ~
bash-3.2$
bash-3.2$ gsi
Gambit v4.9.3
> (define-syntax while
(syntax-rules ()
((_ test code ...)
(let loop ()
(if test
(begin code ... (loop)) )))))
*** ERROR IN (console)@2.18 -- Ill-formed expression
> ,q
bash-3.2$
bash-3.2$
bash-3.2$ gsi -:s
Gambit v4.9.3
> (define-syntax while
(syntax-rules ()
((_ test code ...)
(let loop ()
(if test
(begin code ... (loop)) )))))
*** ERROR -- Ill-formed special form: syntax-error
(##syntax-error %%%%tmp18)
> ,q
bash-3.2$
bash-3.2$
bash-3.2$
bash-3.2$ gsi
Gambit v4.9.3
> (define-syntax while
(lambda (x)
(syntax-case x ()
((_ test code ...)
(syntax
(let loop ()
(if test
(begin code ... (loop)) )))))))
*** ERROR IN (console)@3.22 -- Ill-formed expression
> ,q
bash-3.2$ gsi -:s
Gambit v4.9.3
> (define-syntax while
(lambda (x)
(syntax-case x ()
((_ test code ...)
(syntax
(let loop ()
(if test
(begin code ... (loop)) )))))))
*** ERROR -- Ill-formed special form: syntax-error
(##syntax-error %%%%tmp18)
>
,q
bash-3.2$
~ ~ ~ ~ script output ENDS ~ ~ ~ ~
I’m using the most up-to-date version of Gambit from the MacPorts
collection (v4.9.3), on a relatively up-to-date MacBook computer to run
these.
What am I missing?
And lastly, does my problem have anything to do with this?
https://github.com/gambit/gambit/issues/384
And if so, is there a newer version of gambit that I can submit to
MacPorts to make macros work again?
Thanks,
- William
More information about the Gambit-list
mailing list