My matrix package actually only provides semi-persistent (a technical term in the data structures world, I guess) matrices. A fully functional one would probably just use a double layered hasheq.<div><br></div><div>Basically, you can always read any older version of the matrix, but you only modify the latest modification. Also, reads to an old version are O(n) where n is the distance (in writes) to the latest but reads to the current version are O(1)</div>
<div><br></div><div>Jay</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 31, 2012 at 6:38 PM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@hashcollision.org" target="_blank">dyoo@hashcollision.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, Oct 31, 2012 at 5:12 PM, Gregory Woodhouse<br>
<<a href="mailto:gregwoodhouse@icloud.com">gregwoodhouse@icloud.com</a>> wrote:<br>
> I've been thinking about whether how to implement matrices in Racket. One obvious option is just to use a vector<br>
<br>
<br>
</div>Oh! That's related to something I was coding up called "multidim" to<br>
do multi-dimensional matrices. Here is the source:<br>
<br>
<a href="https://github.com/dyoo/multidim" target="_blank">https://github.com/dyoo/multidim</a><br>
<br>
I was going to ask the list for a code review to figure out what a<br>
nice API would be. No documentation yet, but does have test cases.<br>
<div class="im"><br>
<br>
<br>
> ;;a matrix with data stored in the vector data<br>
> (struct matrix (rows cols [data #:mutable]))<br>
<br>
<br>
</div>If we're going to use a single mutable vector for data, then we don't<br>
need to mark the field itself as #:mutable. We'd need it if we were<br>
to use set-matrix-data!, but I don't think you're doing that, right?<br>
<div class="im"><br>
<br>
<br>
> Is there a preferred way of doing this sort of thing?<br>
<br>
</div>I'm not sure. I think it really depends on the application. If we<br>
need persistent structures, then probably something like Jay's matrix<br>
package might be helpful:<br>
<br>
<a href="http://planet.racket-lang.org/display.ss?package=matrix.plt&owner=jaymccarthy" target="_blank">http://planet.racket-lang.org/display.ss?package=matrix.plt&owner=jaymccarthy</a><br>
<div class="HOEnZb"><div class="h5">____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>"The glory of God is Intelligence" - D&C 93<br>
</div>