I'm working though SICP and wanted to try out some of the examples in guile. I'm trying the stream examples and wanted an implementation for cons-stream, which I got from this StackOverflow question. However when I type this into guile I get:
guile> (define-syntax cons-stream
(syntax-rules ()
[(cons-stream x y) (cons x (delay y))]))
ERROR: invalid syntax ()
ABORT: (misc-error)
I have no idea what's wrong with this - I've tried replacing () with '(), removing the [ ], but it still doesn't work even though it seems to be valid R5RS. I'm currently on guile 1.8.7, I can't see a package for v2.0.1 which the GNU docs mention, could this be why its not working for me?
Looks like you need to import support for syntax-rules
first (see http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Syntax-Rules.html):
(use-syntax (ice-9 syncase))
Then you need to change the square brackets to parens; after that it should work.
Definitely don't quote the literals list; that's a sequence of identifiers, like lambda
formals, not an expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With