[plt-scheme] Using the struct type identifier as a macro [PATCH]

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Mon Nov 17 13:07:43 EST 2008

On Mon, 17 Nov 2008, Sam TH wrote:

> Can you run the test suite for `match' like this:
>
> % cd collects/tests/match
> % mzscheme plt-match-tests.ss

yes, that passes too:
321 success(es) 0 failure(s) 0 error(s) 321 test(s) run

>
> as well as add some tests for your new feature?  Probably it would be
> easiest to add them to collects/tests/match/examples.ss .

Well, there are really just a couple of tests that make sense:
correct expansion and the arity syntax error.

For the former one, will something like this do?
(define-struct test1 (x y))
(define-struct (test2 test1) (z))

(match (test1 1 2) ((test1 x y) (list x y)))
=> (1 2)
(match (test2 1 2 3) ((test1 x y) (list x y)))
=> (1 2)
(match (test2 1 2 3) ((test2 x y z) (list x y z)))
=> (1 2 3)
(match (test1 1 2) ((test2 x y z) #t) (else #f))
=> #f

Now, the syntax error is harder to autotest. Is there any facility for 
catching syntax errors?

Something like this:
  (match 'foo ((test1 x) #t))
stdin::268: match: wrong number for fields for structure test1: expected 2 
but got 1 at: (x) in: (test1 x)

I can also add a couple of tests in the tests/mzscheme/struct.ss suite.

-- vyzo


Posted on the users mailing list.