[racket] color does not match like other structs

From: Adam Shaw (adamshaw at cs.uchicago.edu)
Date: Wed Aug 29 12:22:58 EDT 2012

Hi all --

This came up perhaps a year ago; I'm writing about pattern matching with the color struct that comes with 2htdp/image. It is inconsistent with struct matching generally.

In the following excerpt, bar and baz are fine, but foo (commented out) causes an error (match: color does not refer to a structure definition):

(require 2htdp/image)

(define-struct my-color (red green blue))

;(define foo 
;  (match (make-color 1 2 3)
;    [(struct color (r g b))
;     (+ r g b)]))

(define bar
  (match (make-my-color 1 2 3)
    [(struct my-color (r g b))
     (+ r g b)]))

(define baz
  (match (make-posn 1 2)
    [(struct posn (x y))
     (+ x y)]))

(I ran this in DrRacket 5.3, Advanced Student.)

I remember discussing with Robby why this is so (I don't remember the internal details, but it has to do with something distinguished about color structs under the hood), but I'm requesting that perhaps the system could be modified such that colors match in a way consistent with other structs. Thanks much.

Regards,

Adam Shaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120829/a02f0d32/attachment.html>

Posted on the users mailing list.