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

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Mon Oct 10 09:19:08 EDT 2011

On Mon, Oct 10, 2011 at 8:38 AM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>
> You would have to expand to something that includes both the static
> and runtime pieces:
>
> (begin (define-values ( ... ) ... )
>          (define-syntaxes ( ... ) ... ))
>
> But that's going to be difficult because ideally you'd just use the
> static binding that define-struct sets up. One approach would be to
> put the define-struct at the top-level but with altered names that you
> control:

Another approach that might work is to use the `#:omit-define-values'
keyword with regular `racket/base' `define-struct':

#lang racket
(define (make-foo . args) args)
(define foo? list?)
(define (foo-x v) (car v))
(define (foo-y v) (cadr v))
(define-struct foo (x y) #:omit-define-values)
(match (make-foo 1 2)
  [(struct foo (x y)) (+ x y)])

-- 
sam th
samth at ccs.neu.edu



Posted on the dev mailing list.