Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 307
Tom Carver Avatar asked May 21 '11 13:05

Tom Carver


1 Answers

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.

like image 151
Ryan Culpepper Avatar answered Sep 19 '22 14:09

Ryan Culpepper