what's wrong with this define-syntax macro in scheme?
Asked Answered
S

1

5

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?

Swiftlet answered 21/5, 2011 at 13:18 Comment(0)
B
8

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.

Benedetta answered 21/5, 2011 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.