[racket] Racket newbie questions

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue May 7 10:13:09 EDT 2013

Hi John,

2013/5/7 John Gateley <racket at jfoo.org>

> Here's a summary of the responses. Thanks to everyone who
> replied. My comments are in [ and ]. Not much new though.
>> 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:

Jens Axel Søgaard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130507/0db590c0/attachment.html>

Posted on the users mailing list.