[racket] Some struct questions

From: Tony Garnock-Jones (tonyg at ccs.neu.edu)
Date: Mon Jul 16 13:01:31 EDT 2012

On 07/16/2012 12:39 PM, Harry Spier wrote:
> what use is having
> access to the constructor without access to the field getters and
> setters.

One possible answer to this is that you can match on a structure with 
just its constructor in scope:

;; s.rkt
#lang racket
(provide foo)
(struct foo (bar baz))

;; other.rkt
(require "s.rkt")
(match (foo 1 2) [(foo a b) (+ a b)])
;; => 3
;; note that neither foo-bar nor foo-baz are in scope


Posted on the users mailing list.