[racket] What do first-class structures achieve?

From: Yi D (plmday at gmail.com)
Date: Thu Mar 13 06:30:36 EDT 2014


The documentation says that struct creates structures that are treated as
values. I can see the motivation for pursuing expressiveness. So what do we
using first-class structures? On the down side, I see some problems. For
example, in
the Beginning Student language, a posn is both a posn? and a struct?.

> (posn? (make-posn 1 2))
> (struct? (make-posn 1 2))

I guess this is because posn is declared to be #:transparent.

In my opinion, exposing the struct? nature of posn undermines abstraction
and breaks
encapsulation. But without declaring it #:transparent, the printer could
not echo
informative response. It seems to me the two aspects: exposing the
struct?nature and
informative result are unnecessarily tangled. If they can be separated, we
may be able
to give informative result and at the same time not to expose the
struct?nature of
structure types.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140313/42217e8c/attachment.html>

Posted on the users mailing list.