[plt-scheme] naming convention for structure constructor vs. wrapper?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Jul 1 13:50:54 EDT 2004

 From the manual:

(define-values (struct:a really-make-a a? a-ref a-set!)
   (make-struct-type 'a #f 2 1 'uninitialized))
(define an-a (really-make-a 'x 'y))
(a-ref an-a 1) ; => 'y
(a-ref an-a 2) ; => 'uninitialized

(define (make-a x y) (really-make-a (symbol> x) (symbol> y)))
(define (symbol> x) (if (symbol? x) x (error 'symbol>)))

(define a-first (make-struct-field-accessor a-ref 0))
(a-first an-a) ; => 'x

(a-first (make-a 'a 'b))

With a few slight enhancements. make-struct-type is the real thing.

-- Matthias

On Jul 1, 2004, at 1:37 PM, Michael Sperber wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>>>>>> "Doug" == Doug Orleans <dougo at place.org> writes:
>
> Doug> I was thinking of using `foo' for the wrapper if it's a macro
> Doug> (and keeping `make-foo' as the constructor procedure), similar
> Doug> to `generic' vs. `make-generic', but then this clashes with the
> Doug> syntax binding produced by `define-struct', which I want to keep
> Doug> so that users can define subtypes (or use match, etc).  Any
> Doug> other ideas?
>
> Use SRFI 9, where you can pick the name of the constructor.  I usually
> choose REALLY-MAKE-xxx for the real constructor, and MAKE-xxx for the
> wrapper.  DEFINE-STRUCT sucks.
>
> -- 
> Cheers =8-} Mike
> Friede, Völkerverständigung und überhaupt blabla



Posted on the users mailing list.