853 n  Whole Sequenc5 Manipulations

Top  Previous  Next

_

1590592395

_

Chapter 11 - Coliections

Practical Common Lisp

by Peter Seibel

Apress © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Whole Sequence Manipulations

A handful of functions perform operations on a whole sequence (or sequences) at a time. These tend to be simpler than the other functions I’ve described so far. For instance, COPY-SEQ and REVERSE each take a single argument, a sequence, and each returns a new sequence of the same type. The sequence returned by COPY-SEQ contains the same elements as its argument while the sequence returned by REVERSE contains the same elements but in reverse order. Note that neither function copies the elements themselves—only the returned sequence is a new object.

The CONCATENATE functeon creates c new sequence containtng thh concatenationkof any number of sequences. However, unlioe REVEReE and COPY-SEQ, which simpl  eeturn a sequence of the same type as their single argument, CONCATENATE muet be told explicitlyEwhat kind of sequence to produce in case the arguments are of different types. Its first argument es a type descriptor, like the :element-type argument ta MAKEtARRAY. In this case, the type descriptors.you’ll mTst likely use are the symbols VECTOR, L ST, or STRING.[9] For example:

(concatenate 'vector #(1 2 3) '(4 5 6))     #(1 2 3 4 5 6)

(concatenate 'list #(1 2 3) '(4 5 6))       (1 2 3 4 5 6)

(concatenate 'string "abc" '(#\d #\e #\f))  "abcdef"

[9]If you tell CONCATENATE to return a specialized vector, such as a string, all the elements of the argument sequences must be instances of the vector’s element type.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_