[racket-dev] struct + match not interacting via a macro

From: Shriram Krishnamurthi (sk at cs.brown.edu)
Date: Sun Oct 9 20:31:03 EDT 2011

What exactly does the struct form of match (in the ASL language) use
to identify the structure?  The following works fine:

(define-struct foo (a b))

(match (make-foo 1 2)
  [(struct foo (x y))
   (+ x y)])

But I have a macro over define-struct for which I get the error

  match: foo does not refer to a structure definition in: foo

(pointing at the "foo" in "struct foo (x y)").

My macro uses build-struct-names to synthesize the names of the
constructor, selectors, etc.  It binds all these names (including the
"struct:foo" name); for good measure I'm also binding "foo".  The
coloring in the Macro Stepper isn't instructive (to me, anyway --
there is only one step of reduction before the error).

Here is the sample output (... elides irrelevant detail):

(define-struct: foo ([a : Number$] [b : Number$]))


     (define-values (foo struct:foo make-foo foo? foo-a set-foo-a!
foo-b set-foo-b!)
       (let ()
           (define-struct foo (a b) #:transparent #:mutable)
           (let ([make-foo
                  (lambda (a b) ...)]
                 [set-foo-a! (lambda (struct-inst new-val) ...)]
                 [set-foo-b! (lambda (struct-inst new-val) ...)])
             (values foo struct:foo make-foo foo? foo-a set-foo-a!
foo-b set-foo-b!))))))

Any ideas?


Posted on the dev mailing list.