[racket] Small and short-lived data structures

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Tue Oct 22 09:58:52 EDT 2013

Matthias Felleisen writes:

 > On Oct 22, 2013, at 6:46 AM, Konrad Hinsen <konrad.hinsen at fastmail.net> wrote:
 > 
 > > structs and vectors once I am in the Typed Racket universe, so I'll
 > > stick to structs for now.
 > 
 > Use vectors. At some point, you will want to iterate over these
 > things or access fields via computation.

That's a good point. Another point in favor of vectors is the
possibility to specialize to flvector.

On the other hand, there are good arguments for structs as well.

Each struct is a distinct type, even if it happens to have the same
structure as some other type. I expect to have several types
represented by three real numbers, for example, so being able to
distinguish them is useful.  Using #:transparent structs, I get

1) values printed with type information (good for users)

2) more precise type checking in Typed Racket

I also get guaranteed immutability. With vectors, I can always use
vector-immutable to make mine, but I can't prevent people from
creating mutable vectors, intentionally or by accident, and using
them in place of "my" type.

Konrad.

Posted on the users mailing list.