[racket] Mutation of structure elements

From: Danny Yoo (dyoo at hashcollision.org)
Date: Wed Oct 31 20:38:44 EDT 2012

On Wed, Oct 31, 2012 at 5:12 PM, Gregory Woodhouse
<gregwoodhouse at icloud.com> wrote:
> I've been thinking about whether how to implement matrices in Racket. One obvious option is just to use a vector


Oh!  That's related to something I was coding up called "multidim" to
do multi-dimensional matrices.  Here is the source:

    https://github.com/dyoo/multidim

I was going to ask the list for a code review to figure out what a
nice API would be.  No documentation yet, but does have test cases.



> ;;a matrix with data stored in the vector data
> (struct matrix (rows cols [data #:mutable]))


If we're going to use a single mutable vector for data, then we don't
need to mark the field itself as #:mutable.  We'd need it if we were
to use set-matrix-data!, but I don't think you're doing that, right?



> Is there a preferred way of doing this sort of thing?

I'm not sure.  I think it really depends on the application.  If we
need persistent structures, then probably something like Jay's matrix
package might be helpful:

    http://planet.racket-lang.org/display.ss?package=matrix.plt&owner=jaymccarthy

Posted on the users mailing list.