Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pattern matching in Scheme

Name: Anonymous 2010-07-16 11:19

I’ve got this OCaml codebase I’d like to convert to Scheme, partly to learn the language, partly because I keep getting hit by OCaml’s weird syntax.

Anyway, the aforementioned code makes heavy use of pattern matching. I’ve searched the documentation of DrScheme (now Racket), and found the module that seems to be perfect for me; however, I can’t seem to be able to make even the most basic example work: the code


(require scheme/match)

(define-struct tree (val left right))

(match (make-tree 0 (make-tree 1 #f #f) #f)
      [(tree a (tree b  _ _) _) (list a b)])


gives the error match: syntax error in pattern in: (tree a (tree b _ _) _)

Any of you have experience with pattern matching in Scheme?

Name: Anonymous 2010-07-16 16:08

>>9
What I need is type matching
Well, you can do this portably, but it is often separate from the normal pattern matcher. There's no reason that this should be the case if you are using R6RS, but no-one has yet integrated the two.
locking myself into an open–source implementation of Scheme doesn’t look too bad.
It isn't, except for when two incompatible Scheme have libraries that you would like to use in the same project :)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List