[plt-scheme] define-struct Style Question

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Fri Nov 30 14:12:00 EST 2007

I often use structs as the basis for an abstraction.  They are simple,
convenient, and built into PLT Scheme.  However, more often than not, I want
some slight variation on the normally generated interface.  For example, I
often want a different constructor because some of the slots are computed or
are internal to the abstraction.  In the past I have been using
make-struct-type in these cases (with <name>-constructor) and coding a new
make-<name> function and generating the field accessors and mutators using
make-struct-field-field-accessor or make-struct-field-mutator (or coding
accessor or mutator functions if there do more than just get or set a
slot).  This works, but it's a pain and results in a lot of repetitive
boilerplate kind of code.  [And, I can't easily extent the struct type with
new sub-types.  (There seems to be additional syntax information generated
by define-struct that isn't generated by make-struct-type.)  But, I'm okay
with that.  I tend to 'move up to' classes if I need inheritance, etc.]
I've seen that some people use define-struct and then create new
constructors (or accessors and mutators) that are renamed when they are
provided by the module containing them.  This works, but you have different
name within the module than externally.  [This difference is often minimized
to just a prefix added.]
I am leaning toward changing my style to the use of define-struct with
renames to provide struct-based abstractions.  But, are there other methods
that might be better.  [Generally, better to me means more readable and
maintainable.]
Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071130/f7a04a93/attachment.html>

Posted on the users mailing list.