Arc Forumnew | comments | leaders | submitlogin
Simple Vectors
4 points by bcater 6141 days ago | 2 comments
I wrote some extremely simple code for vectors. The supported operations are detailed in the README, and you can get the zip of everything at http://www.monkeytex.com/random/vec.zip. In short, you get (vec) to create a vector, (vec-add) to add an element, (vec-get) to get an element at the given index, and (len) to get the length of the vector.

If someone could make it better or cleaner, I'd love to see it. This was good enough for me, but I'm sure it will be inadequate for some.



1 point by kennytilton 6140 days ago | link

I am puzzled by how (let (t (cdr v))...) could work for you in vec-get when it should be (let tbl (cdr v)...) -- note that as an aside I am avoiding rebinding t just from long CL experience. Also, it seems unusable because no one wants to rebind some local variable holding the vector just because they added an element. And it is unworkable because you make a new cons of count and hash but you keep the same hash, so anyone with a binding with a lower count who now goes to add will be writing over values added by other code working on the same vector (say if I pass the vector to a subroutine for further work and then resume work on it myself). My final concern is finding a hashtable inside something called "vector". :) Anyway, the fix is to modify the car of the "vector" when changing the count instead of consing up a new count-hash pair. But really I would mush rather see a size declared when creating the vector and then requiring an index on the add (in which case it is more of a set).

-----

1 point by bcater 6139 days ago | link

"My final concern is finding a hashtable inside something called \"vector\"."

Yeah, I didn't actually know how to create a vector, so I used this instead.

Also, I realized just after posting that setting the car really was the right way to do this (all else being equal, of course).

-----