1.4.12 Sequences
(coerce x y) → t |
x : (if (equal y 'list) (stringp x) (if (equal y 'string) (character-listp x) nil)) |
y : t |
Coerces a character list into a string or a string into a list. The second argument must be either 'string or 'list.
Examples: |
> (coerce "hello" 'list) |
'(#\h #\e #\l #\l #\o) |
> (coerce '(#\h #\e #\l #\l #\o) 'string) |
"hello" |
(concatenate sym seq ...) |
Concatenates strings or lists together. If the first argument is 'string, concatenate will accept strings to concatenate. If the first argument is 'list, it will accept lists.
Examples: |
> (concatenate 'string "ab" "cd" "ef") |
"abcdef" |
> (concatenate 'string "ab") |
"ab" |
> (concatenate 'string) |
"" |
> (concatenate 'list '(a b) '(c d) '(e f)) |
'(a b c d e f) |
> (concatenate 'list) |
'() |
(length x) → t |
x : (or (true-listp x) (stringp x)) |
Returns the number of elements in the given list, or the number of characters in the given string.
(position x seq) → t |
x : t |
seq : (or (stringp seq) (and (true-listp seq) (or (eqlablep x) (eqlable-listp seq)))) |
Determines the (0-based) position in seq at which x first occurs. Uses eql for comparisons. Returns nil if x is not found.
(position-eq x lst) → t |
x : t |
lst : (and (true-listp lst) (or (symbolp x) (symbol-listp lst))) |
Determines the (0-based) position in lst at which x first occurs. Uses eq for comparisons. Returns nil if x is not found.
Example: |
> (position-eq 'a (list 'c 'b 'a)) |
2 |
(position-equal x seq) → t |
x : t |
seq : (or (stringp seq) (true-listp seq)) |
Determines the (0-based) position in seq at which x first occurs. Uses equal for comparisons. Returns nil if x is not found.
Examples: |
> (position-equal 'a (list 'c 'b 'a)) |
2 |
> (position-equal #\o "lion") |
2 |
> (position-equal "5" (list "1" "3" "5")) |
2 |
(subseq seq i j) → t |
seq : (or (true-listp seq) (stringp seq)) |
i : ((integerp i) (<= 0 i)) |
j : (and (or (null j) (and (integerp j) (<= j (length seq)))) (<= i (or j (length seq)))) |
Returns a subsection of the given sequence, starting at the ith (inclusive, 0-based) position and ending at the jth (exclusive) position. If j is nil, then subseq will return the list to the end.
Examples: |
> (subseq "0123456789" 2 6) |
"2345" |
> (subseq (list 0 1 2 3 4 5) 2 4) |
'(2 3) |
> (subseq (list 0 1 2 3 4 5) 2 nil) |
'(2 3 4 5) |
(substitute new old seq) → t |
new : t |
old : t |
seq : (or (and (stringp seq) (characterp new)) (and (true-listp seq) (or (eqlablep old) (eqlable-listp seq)))) |
Substitutes every occurrence of old with new in the given list or string.
Examples: |
> (substitute 2 1 (list 1 1 1 3 1 1 1)) |
'(2 2 2 3 2 2 2) |
> (substitute #\Z #\a "abcdabcdabcd") |
"ZbcdZbcdZbcd" |