1.4.8 Lists
List functions can also be found in the sections on Association Lists, Sets, and Sequences.
(cons x y) |
(consp x) |
Examples: |
> (consp nil) |
'() |
> (consp 5) |
'() |
> (consp "string") |
'() |
> (consp (cons 1 nil)) |
't |
> (consp '(1 2 3)) |
't |
(append lst ...) |
Examples: |
> (append nil nil) |
'() |
> (append nil (list 1 2)) |
'(1 2) |
> (append (list 1 2) (list 3 4)) |
'(1 2 3 4) |
(binary-append x y) → t |
x : (true-listp x) |
y : t |
Examples: |
> (binary-append (list 1 2 3) (list 4 5 6)) |
'(1 2 3 4 5 6) |
> (binary-append (list 1 2 3) 4) |
'(1 2 3 . 4) |
> (binary-append 5 "<-error") |
/home/cce/git/planet/dracula/lang/primitive-procedures/acl2- |
prims.ss: (region Dracula Program) broke the contract |
(xargs :guard (true-listp x)) on binary-append; |
x = 5 |
y = "<-error" |
(mv x ...) |
Example: |
> (mv 1 2 3 4) |
'(1 2 3 4) |
(revappend x y) → t |
x : (true-listp x) |
y : t |
Examples: |
> (revappend nil nil) |
'() |
> (revappend nil (list 1 2)) |
'(1 2) |
> (revappend (list 1 2) (list 3 4)) |
'(2 1 3 4) |
> (revappend (list 1 2) 3) |
'(2 1 . 3) |
(list elem ...) |
(list* elem ... tail) |
(atom-listp x) → t |
x : t |
Examples: |
> (atom-listp (list 2 3 4)) |
't |
> (atom-listp (list (list 23 34) 45)) |
'() |
(character-listp x) → t |
x : t |
Examples: |
> (character-listp (list #\a #\b)) |
't |
> (character-listp (list #\a "b")) |
'() |
(eqlable-listp x) → t |
x : t |
Examples: |
> (eqlable-listp nil) |
't |
> (eqlable-listp (cons 4 nil)) |
't |
> (eqlable-listp t) |
'() |
(integer-listp x) → t |
x : t |
Examples: |
> (integer-listp nil) |
't |
> (integer-listp (list 24 -21 95)) |
't |
> (integer-listp (list 53 44 "number")) |
'() |
(keyword-value-listp x) → t |
x : t |
Examples: |
> (keyword-value-listp (list :a 1 :b 2 :c 3)) |
't |
> (keyword-value-listp (list 'a 1 'b 'c 3)) |
'() |
(proper-consp x) → t |
x : t |
Examples: |
> (proper-consp nil) |
'() |
> (proper-consp (list 1 2 3)) |
't |
> (proper-consp (cons 1 2)) |
'() |
(rational-listp x) → t |
x : t |
Examples: |
> (rational-listp (list 1 2/5 3)) |
't |
> (rational-listp (list 1 2/5 "number")) |
'() |
(standard-char-listp x) → t |
x : t |
Examples: |
> (standard-char-listp (list #\a #\b #\c)) |
't |
> (standard-char-listp (list 1 2 3)) |
'() |
(string-listp x) → t |
x : t |
Examples: |
> (string-listp (list "ab" "cd" "ef")) |
't |
> (string-listp (list 1 2 3)) |
'() |
(symbol-listp x) → t |
x : t |
Examples: |
> (symbol-listp (list 'ab 'cd 'ef)) |
't |
> (symbol-listp (list 1 2 3)) |
'() |
(true-list-listp x) → t |
x : t |
Examples: |
> (true-list-listp (list 1 2 3 4 5)) |
'() |
> (true-list-listp '((1) (2) (3) (4) (5))) |
't |
(true-listp x) → t |
x : t |
Examples: |
> (true-listp (list 1 2 3 4 5)) |
't |
> (true-listp "list") |
'() |
Examples: |
> (butlast (list 1 2 3) 1) |
'(1 2) |
> (butlast (list 1 2 3) 2) |
'(1) |
> (butlast (list 1 2 3) 3) |
'() |
(fix-true-list x) → t |
x : t |
Examples: |
> (fix-true-list (list 1 2 3)) |
'(1 2 3) |
> (fix-true-list (cons 1 (cons 2 3))) |
'(1 2) |
> (fix-true-list "abc") |
'() |
> (fix-true-list 5) |
'() |
(make-list n) → true-listp |
n : (and (integerp n) (<= 0 n)) |
(reverse x) → t |
x : (or (true-listp x) (stringp x)) |
(update-nth n v lst) → t |
n : (and (integerp n) (<= 0 n)) |
v : t |
lst : (true-listp l) |
Examples: |
> (update-nth 0 'z '(a b c d e)) |
'(z b c d e) |
> (update-nth 8 'z '(a b c d e)) |
'(a b c d e () () () z) |
(first lst) |
(second lst) |
(third lst) |
(fourth lst) |
(fifth lst) |
(sixth lst) |
(seventh lst) |
(eighth lst) |
(ninth x) |
(tenth lst) |
(last lst) |
(rest lst) |