2.4.12 Sequences
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" |
> (coerce "hello" 'blah) |
Dracula program broke the contract (->r ((x ...) |
(result-type ...)) ...) on here; expected <(symbols (quote |
list) (quote string))>, given: blah |
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) |
() |
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.
Examples: |
> (length (list 1 2 3 4 5)) |
5 |
> (length "hello") |
5 |
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.
Examples: |
> (position 1 (list 3 2 1)) |
2 |
> (position #\o "lion") |
2 |
> (position 5 (list 1 2 3)) |
() |
> (position "5" (list "1" "3" "5")) |
Dracula program broke the contract (->r ((x ...) (y ...)) |
...) on here; expected <eqlablep>, given: "1" |
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.
Examples: |
> (position-eq 'a (list 'c 'b 'a)) |
2 |
> (position-eq 5 (list 1 2 3 4 5)) |
Dracula program broke the contract (->r ((x ...) (y ...)) |
...) on here; expected <symbolp>, given: 1 |
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 |
> (position-equal 5 12345) |
Dracula program broke the contract (-> (or/c "nil" |
(cons/c any/c any/c)) any) on here; expected <(or/c nil |
(cons/c any/c any/c))>, given: 12345 |
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) |
-: expects type <number> as 1st argument, given: (); other |
arguments were: 2 |
> (subseq "abcdefgh" 4 1) |
substring: ending index 1 out of range [4, 8] for string: |
"abcdefgh" |
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" |