<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi all --<br><br>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.</div><div><br class="webkit-block-placeholder"></div><div>In the following excerpt, bar and baz are fine, but foo (commented out) causes an error (<font class="Apple-style-span" face="'Courier New'">match: color does not refer to a structure definition</font>):</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">(require 2htdp/image)</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define-struct my-color (red green blue))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">;(define foo </font></div><div><font class="Apple-style-span" face="'Courier New'">; (match (make-color 1 2 3)</font></div><div><font class="Apple-style-span" face="'Courier New'">; [(struct color (r g b))</font></div><div><font class="Apple-style-span" face="'Courier New'">; (+ r g b)]))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define bar</font></div><div><font class="Apple-style-span" face="'Courier New'"> (match (make-my-color 1 2 3)</font></div><div><font class="Apple-style-span" face="'Courier New'"> [(struct my-color (r g b))</font></div><div><font class="Apple-style-span" face="'Courier New'"> (+ r g b)]))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define baz</font></div><div><font class="Apple-style-span" face="'Courier New'"> (match (make-posn 1 2)</font></div><div><font class="Apple-style-span" face="'Courier New'"> [(struct posn (x y))</font></div><div><font class="Apple-style-span" face="'Courier New'"> (+ x y)]))</font></div></div>
<br><div>(I ran this in DrRacket 5.3, Advanced Student.)</div><div><br></div><div>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.</div><div><br></div><div>Regards,</div><div><br></div><div>Adam Shaw</div></body></html>