Package: split-sequence

Function split-sequence

Lambda List

split-sequence (delimiter sequence &key start end from-end count remove-empty-subseqs test test-not key)

Arguments

delimiter -- an object
sequence -- a proper sequence.
start, end -- bounding index designators of sequence. The defaults for start and end are 0 and nil, respectively.
from-end -- a generalized boolean. The default is false.
count -- an integer or nil. The default is nil.
remove-empty-subseqs -- a generalized boolean. The default is false.
test -- a designator for a function of two arguments that returns a generalized boolean.
test-not -- a designator for a function of two arguments that returns a generalized boolean.
key -- a designator for a function of one argument, or nil.

Return Value

Returns a proper list list and an index into the sequence.

Details

Return a list of subsequences in sequence delimited by delimiter.

list is a list of sequences of the same kind as sequence that has elements consisting of subsequences of sequence that were delimited in the argument by elements satisfying the test. index is an index into sequence indicating the unprocessed region, suitable as an argument to subseq to continue processing in the same manner if desired.

The count argument, if supplied, limits the number of subsequences in the first return value; if more than count delimited subsequences exist in sequence, the count leftmost delimited subsequences will be in order in the first return value, and the second return value will be the index into sequence at which processing stopped.

If from-end is non-null, sequence is conceptually processed from right to left, accumulating the subsequences in reverse order; from-end only makes a difference in the case of a non-null count argument. In the presence of from-end, the count rightmost delimited subsequences will be in the order that they are in sequence in the first return value, and the second is the index indicating the end of the unprocessed region.

The start and end keyword arguments permit a certain subsequence of the sequence to be processed without the need for a copying stage; their use is conceptually equivalent to partitioning the subsequence delimited by start and end, only without the need for copying.

If remove-empty-subseqs is null (the default), then empty subsequences will be included in the result.

In all cases, the subsequences in the first return value will be in the order that they appeared in sequence.

Examples

SPLIT-SEQUENCE> (split-sequence #Space "A stitch in time saves nine.")
⇒ ("A" "stitch" "in" "time" "saves" "nine.")
 ⇒ 28

SPLIT-SEQUENCE> (split-sequence #, "foo,bar ,baz, foobar , barbaz,") ⇒ ("foo" "bar " "baz" " foobar " " barbaz" "") ⇒ 30
 

See also

2012-12-29