9.0
top
← prev up next →

Persistent VectorsπŸ”— i

This provides an implementation of persistent, immutable vectors. They are implemented as 32-way bitmapped tries with a tail to provide truly constant time appends to the end of the vector. Data is shared between a vector and its subsequent functional modifications.

The persistent vectors provided by this module implement the gen:equal+hash generic interface, so they may be used as keys, and equal? will perform deep comparisons. Additionally, they implement three interfaces from data/collection, gen:countable , gen:collection , and gen:sequence , which contain the interface for interacting with them.

1Example UsageπŸ”— i

Persistent vectors may be created using the pvector constructor.

> (pvector 1234)

#pv[1 2 3 4]

Afterwards, they can be interacted with via the functions from data/collection.

> (conj (pvector 1234)5)

#pv[1 2 3 4 5]

It is often useful to create an empty vector using (pvector ), then extending it with some other sequence.

#pv[0 1 2 3 4 5 6 7 8 9]

2Native API ReferenceπŸ”— i

The interface provided by data/pvector is small. Most of the functions for manipulating persistent vectors reside in data/collection. However, some functions are specific to persistent vectors.

procedure

( pvector? v)boolean?

v:any/c
Returns #t if v is a persistent vector, otherwise returns #f.

procedure

( pvector v...)pvector?

v:any/c
Creates a new persistent vector with the v arguments as its contents. Calling this function with multiple arguments simply performs extend on the empty vector, (pvector ), so it is no more efficient than using extend directly.

Creates a new persistent vector of length n by applying proc to each integer, i, from 0 to n-1 in order. The ith element of the vector will be the value of (proci).

Creates a new persistent vector of length n, with each element filled with the value v.

3ComprehensionsπŸ”— i

syntax

( for/pvector (for-clause...)body-or-break...body)

syntax

( for*/pvector (for-clause...)body-or-break...body)

Equivalent to for/sequence or for*/sequence combined with (extend (pvector )... ) to collect the results into a persistent vector.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /