[racket] Racket newbie questions

From: John Gateley (racket at jfoo.org)
Date: Tue May 7 11:16:43 EDT 2013

> 2013/5/7 John Gateley <racket at jfoo.org>
>>> 5) Is there an implementation of vectors that can change in size?
>>> Like C++'s std::vector?
>> http://docs.racket-lang.org/**data/gvector.html<http://docs.racket-lang.org/data/gvector.html>
>> [This is close, but I don't see an operation to explicitly grow the
>> vector, other than adding one element at the end. For some algorithms,
>> you want to grow the vector exponentially - doubling the size instead
>> of adding one element.]
> That is exactly what happens behind the scenes.
> A gvector is implemented as a structure containing a vector v
> and a number n. The vector holds the elements in the gvector and
> n represents the number of elements used in the vector n.
> Each time the vector v is filled, a new vector of the double size
> is allocated and the elements are copied into the new vector.
> The exact details can be studied here:
> https://github.com/plt/racket/blob/master/collects/data/gvector.rkt

Excellent! Thanks very much.


Posted on the users mailing list.