Vector-add function not available

I want to add a single element at the end of a vector, but I cannot find a function like vector-add. I am assuming that is because it acts as a deterrent not to try and do this.

Coming from a Clojure environment I am used to adding an element to the end of a vector and Clojure makes this efficient.

I can of course write a vector-add function using vector-append, but I want to know if there is a better solution before implementing my own vector-add.

I would prefer to keep using immutable data structures if possible.

1 Like

I am assuming that is because it acts as a deterrent not to try and do this.

Yes.

I would prefer to keep using immutable data structures if possible.

If you are comfortable using the development version, then you can use treelist:

https://users.cs.utah.edu/plt/snapshots/current/doc/reference/treelist.html#(mod-path._racket%2Ftreelist)

Get it here: Racket: Snapshot: 2024-02-14-fa06ed5f44

If not, use a growable vector.

https://docs.racket-lang.org/data/gvector.html

Awesome thanks for the quick reply.

I will have a look at the development version for treelist.
I know about growable vectors, but they are mutable, which I would prefer to avoid.

Am I correct in my assumption that it looks like treelist will make into the next release of Racket?

Am I correct in my assumption that it looks like treelist will make into the next release of Racket?

Yes.

I think, treelist is just what you are looking for.

Treelist looks like the answer to me too :slight_smile: