Você está na página 1de 26

Quick Reference

lc cl Common

Common Lisp Quick Reference Revision 123 [2011-01-09]


Copyright © 2008, 2009, 2010, 2011 Bert Burgemeister
LTEX source: http://clqr.berlios.de
A

Permission is granted to copy, distribute and/or modify this document under the
terms of the GNU Free Documentation License, Version 1.2 or any later version
published by the Free Software Foundation; with no Invariant Sections, no Front-
Cover Texts and no Back-Cover Texts. http://www.gnu.org/licenses/fdl.html
lisp
Bert Burgemeister
Common Lisp Quick Reference

Contents
1 Numbers 3 9.5 Control Flow . . . 19
1.1 Predicates . . . . 3 9.6 Iteration . . . . 20
1.2 Numeric Functns . 3 9.7 Loop Facility . . . 21
1.3 Logic Functions . 4
10 CLOS 23
1.4 Integer Functions . 5
10.1 Classes . . . . . 23
1.5 Implementation-
10.2 Generic Functns . 24
Dependent . . . . 6
10.3 Method Combi-
2 Characters 6 nation Types . . . 26
3 Strings 7 11 Conditions and Errors 27
4 Conses 8 12 Types and Classes 29
4.1 Predicates . . . . 8
4.2 Lists . . . . . . 8 13 Input/Output 31
4.3 Association Lists . 9 13.1 Predicates . . . . 31
4.4 Trees . . . . . . 10 13.2 Reader . . . . . 31
4.5 Sets . . . . . . 10 13.3 Character Syntax . 32
13.4 Printer . . . . . 33
5 Arrays 10 13.5 Format . . . . . 35
5.1 Predicates . . . . 10 13.6 Streams . . . . . 38
5.2 Array Functions . 10 13.7 Paths and Files . . 39
5.3 Vector Functions . 11
14 Packages and Symbols 41
6 Sequences 12
14.1 Predicates . . . . 41
6.1 Seq. Predicates . . 12 14.2 Packages . . . . 41
6.2 Seq. Functions . . 12 14.3 Symbols . . . . . 42
7 Hash Tables 14 14.4 Std Packages . . 43
8 Structures 15 15 Compiler 43
15.1 Predicates . . . . 43
9 Control Structure 15
15.2 Compilation . . . 43
9.1 Predicates . . . . 15
15.3 REPL & Debug . 44
9.2 Variables . . . . 16
15.4 Declarations . . . 45
9.3 Functions . . . . 16
9.4 Macros . . . . . 18 16 External Environment 46

Typographic Conventions
Fu M sO gF var co
name; name; name; name; name; ∗name∗; name
⊲ Symbol defined in Common Lisp; esp. function, macro,
special operator, generic function, variable, constant.

them ⊲ Placeholder for actual code.

me ⊲ Literal text.

[foo bar ] ⊲ Either one foo or nothing; defaults to bar.

foo ∗ ; {foo}∗ ⊲ Zero or more foos.

foo + ; {foo}+ ⊲ One or more foos.

foos ⊲ English plural denotes a list argument.


8
<foo
{foo bar baz }; bar ⊲ Either foo, or bar , or baz .
:
baz

<˛˛foo
˛bar ⊲ Anything from none to each of foo, bar , and baz .
:˛˛
baz

c
foo ⊲ Argument foo is not evaluated.

g
bar ⊲ Argument bar is possibly modified.
P∗ sO
foo ⊲ foo ∗ is evaluated as in progn; see p. 19.

foo; bar ; baz ⊲ Primary, secondary, and nth return value.


2 n

T; NIL ⊲ t, or truth in general; and nil or ().

2
Common Lisp Quick Reference

1 Numbers
1.1 Predicates
Fu
(= number + )
Fu
(/= number + )
⊲ T if all number s, or none, respectively, are equal in value.
Fu
(> number + )
Fu
(>= number + )
Fu
(< number + )
Fu
(<= number + )
⊲ Return T if number s are monotonically decreasing,
monotonically non-increasing, monotonically increasing, or
monotonically non-decreasing, respectively.
Fu
(minusp a)
Fu
(zerop a) ⊲ T if a < 0, a = 0, or a > 0, respectively.
Fu
(plusp a)
Fu
(evenp integer )
Fu ⊲ T if integer is even or odd, respectively.
(oddp integer)
Fu
(numberp foo)
Fu
(realp foo)
Fu
(rationalp foo)
Fu
(floatp foo) ⊲ T if foo is of indicated type.
Fu
(integerp foo)
Fu
(complexp foo)
Fu
(random-state-p foo)

1.2 Numeric Functions


Fu
(+ a 0 ∗ ) P Q
Fu ⊲ Return a or a, respectively.
(∗ a 1 ∗ )
Fu
(– a b ∗ )
Fu
(/ a b ∗ ) P Q
⊲ Return a − b or a/ b, respectively. Without any bs,
return −a or 1/a, respectively.
Fu
(1+ a)
Fu ⊲ Return a + 1 or a − 1, respectively.
(1– a)
M ff
incf ]
( M place [delta 1 ])
decf
⊲ Increment or decrement the value of place by delta. Re-
turn new value.
Fu
(exp p)
Fu ⊲ Return ep or bp , respectively.
(expt b p)
Fu
(log a [b]) ⊲ Return logb a or, without b, ln a.
Fu
(sqrt n) √
Fu ⊲ n in complex or natural numbers, respectively.
(isqrt n)
Fu
(lcm integer ∗ 1 )
Fu
(gcd integer ∗ )
⊲ Least common multiple or greatest common denomina-
tor, respectively, of integers. (gcd) returns 0.
co
pi ⊲ long-float approximation of π, Ludolph’s number.
Fu
(sin a)
Fu
(cos a) ⊲ sin a, cos a, or tan a, respectively. (a in radians.)
Fu
(tan a)
Fu
(asin a)
Fu ⊲ arcsin a or arccos a, respectively, in radians.
(acos a)
Fu a
(atan a [b 1 ]) ⊲ arctan b
in radians.
Fu
(sinh a)
Fu
(cosh a) ⊲ sinh a, cosh a, or tanh a, respectively.
Fu
(tanh a)

3
Common Lisp Quick Reference Common Lisp Quick Reference
Fu
(asinh a) NTHCDR 8 READ- SINGLE-FLOAT- THROW 20
Fu
(acosh a) ⊲ asinh a, acosh a, or atanh a, respectively. NULL 8, 30 CHAR-NO-HANG 31 NEGATIVE-EPSILON TIME 45
Fu NUMBER 30 READ-DELIMITED- 6 TO 21
(atanh a) NUMBERP 3 LIST 31 SINH 3 TRACE 44
NUMERATOR 4 READ-FROM-STRING SIXTH 8 TRANSLATE-
Fu NUNION 10 31 SLEEP 20 LOGICAL-
(cis a) ⊲ Return ei a = cos a + i sin a. READ-LINE 31 SLOT-BOUNDP 23 PATHNAME 40
READ-PRESERVING- SLOT-EXISTS-P 23 TRANSLATE-
ODDP 3
Fu WHITESPACE 31 SLOT-MAKUNBOUND PATHNAME 40
(conjugate a) ⊲ Return complex conjugate of a. OF 21
OF-TYPE 21
READ-SEQUENCE 32 24 TREE-EQUAL 10
READER-ERROR 30 SLOT-MISSING 24 TRUENAME 40
ON 21
Fu READTABLE 30 SLOT-UNBOUND 24 TRUNCATE 4
(max num + ) OPEN 38
READTABLE-CASE 32 SLOT-VALUE 24 TWO-WAY-STREAM
Fu ⊲ Greatest or least, respectively, of nums. OPEN-STREAM-P 31
(min num + ) OPTIMIZE 45
READTABLEP 31
REAL 30
SOFTWARE-TYPE 46
SOFTWARE-VERSION
30
TWO-WAY-STREAM-
OR 19, 26, 29, 33
REALP 3 46 INPUT-STREAM 38
8 Fu Fu 9 OTHERWISE 19, 29
REALPART 4 SOME 12 TWO-WAY-STREAM-
>
>{round fround} >
>
OUTPUT-STREAM-P
REDUCE 14 SORT 12 OUTPUT-STREAM
< Fu Fu = 31
{floor ffloor} REINITIALIZE- SPACE 6, 45 38
( Fu Fu n [d 1 ]) INSTANCE 24 SPECIAL 45 TYPE 42, 45
>
>{ ceiling fceiling} >
> PACKAGE 30 REM 4 SPECIAL- TYPE-ERROR 30
: Fu Fu ; PACKAGE-ERROR 30 REMF 16 OPERATOR-P 43 TYPE-ERROR-DATUM
{truncate ftruncate} PACKAGE-ERROR- REMHASH 14 SPEED 45 29
PACKAGE 28 REMOVE 13 SQRT 3 TYPE-ERROR-
⊲ Return as integer or float, respectively, n/d rounded, or PACKAGE-NAME 41 REMOVE- STABLE-SORT 12 EXPECTED-TYPE 29
rounded towards −∞, +∞, or 0, respectively; and remain- PACKAGE- DUPLICATES 13 STANDARD 26 TYPE-OF 29
2 NICKNAMES 41 REMOVE-IF 13 STANDARD-CHAR TYPECASE 29
der. PACKAGE- REMOVE-IF-NOT 13 6, 30 TYPEP 29
SHADOWING- REMOVE-METHOD 25 STANDARD-CHAR-P 6
 Fu ff SYMBOLS 42 REMPROP 16 STANDARD-CLASS 30
UNBOUND-SLOT 30
mod PACKAGE-USE-LIST 41 RENAME-FILE 40 STANDARD-GENERIC-
( Fu n d) PACKAGE- RENAME-PACKAGE 41 FUNCTION 30
UNBOUND-
rem USED-BY-LIST 41 REPEAT 23 STANDARD-METHOD
SLOT-INSTANCE 28
Fu Fu UNBOUND-VARIABLE
⊲ Same as floor or truncate, respectively, but return re- PACKAGEP 41 REPLACE 13 30
30
PAIRLIS 9 REQUIRE 42 STANDARD-OBJECT
mainder only. PARSE-ERROR 30 REST 8 30
UNDEFINED-
PARSE-INTEGER 8 FUNCTION 30
RESTART 30 STEP 45
Fu PARSE-NAMESTRING UNEXPORT 42
RESTART-BIND 28 STORAGE-
(random limit [state ∗random-state∗
var ]) 39 RESTART-CASE 28 CONDITION 30
UNINTERN 41
UNION 10
⊲ Return non-negative random number less than limit, and PATHNAME 30, 40 RESTART-NAME 28 STORE-VALUE 28
UNLESS 19, 21
PATHNAME-DEVICE RETURN 20, 21 STREAM 30
of the same type. 39 RETURN-FROM 20 STREAM-
UNREAD-CHAR 31
PATHNAME- UNSIGNED-BYTE 30
REVAPPEND 9 ELEMENT-TYPE 29
Fu ˆ ˜ DIRECTORY 39 REVERSE 12 STREAM-ERROR 30
UNTIL 23
(make-random-state {state NIL T} NIL ) PATHNAME-HOST 39 ROOM 46 STREAM-
UNTRACE 45
PATHNAME-MATCH-P UNUSE-PACKAGE 41
⊲ Copy of random-state object state or of the current ran- 31
ROTATEF 16 ERROR-STREAM 28
UNWIND-PROTECT 20
ROUND 4 STREAM-EXTERNAL-
dom state; or a randomly initialized fresh random state. PATHNAME-NAME 39 ROW-MAJOR-AREF 10 FORMAT 39
UPDATE-INSTANCE-
FOR-DIFFERENT-
PATHNAME-TYPE 39 RPLACA 9 STREAMP 31
var PATHNAME-VERSION CLASS 24
RPLACD 9 STRING 7, 30
∗random-state∗ ⊲ Current random state. 39 STRING-CAPITALIZE 7
UPDATE-INSTANCE-
PATHNAMEP 31 FOR-REDEFINED-
SAFETY 45 STRING-DOWNCASE 7
Fu PEEK-CHAR 31 CLASS 24
SATISFIES 29 STRING-EQUAL 7
(float-sign num-a [num-b 1 ]) ⊲ num-b with num-a’s sign. PHASE 4 SBIT 11 STRING-GREATERP 7
UPFROM 21
PI 3 UPGRADED-ARRAY-
SCALE-FLOAT 6 STRING-LEFT-TRIM 7
Fu PLUSP 3 ELEMENT-TYPE 29
SCHAR 8 STRING-LESSP 7
(signum n) POP 9 SEARCH 13 STRING-NOT-EQUAL 7
UPGRADED-
COMPLEX-
⊲ Number of magnitude 1 representing sign or phase of n. POSITION 13 SECOND 8 STRING-
PART-TYPE 6
POSITION-IF 13 SEQUENCE 30 NOT-GREATERP 7
POSITION-IF-NOT 13 UPPER-CASE-P 6
Fu SERIOUS-CONDITION STRING-NOT-LESSP 7
UPTO 21
(numerator rational ) PPRINT 33 30 STRING-RIGHT-TRIM
USE-PACKAGE 41
Fu PPRINT-DISPATCH 35 SET 16 7
(denominator rational ) PPRINT-EXIT-IF-LIST- SET-DIFFERENCE 10 STRING-STREAM 30
USE-VALUE 28
EXHAUSTED 34 USER-HOMEDIR-
⊲ Numerator or denominator, respectively, of rational ’s PPRINT-FILL 34
SET- STRING-TRIM 7
PATHNAME 40
DISPATCH-MACRO- STRING-UPCASE 7
canonical form. PPRINT-INDENT 34 CHARACTER 32 STRING/= 7
USING 21
PPRINT-LINEAR 34 SET-EXCLUSIVE-OR STRING< 7
Fu PPRINT-LOGICAL- STRING<= 7
(realpart number ) 10 V 37
Fu BLOCK 34 SET-MACRO- STRING= 7 VALUES 17, 29
(imagpart number ) PPRINT-NEWLINE 35 CHARACTER 32 STRING> 7 VALUES-LIST 17
PPRINT-POP 34 SET-PPRINT- STRING>= 7 VARIABLE 42
⊲ Real part or imaginary part, respectively, of number . PPRINT-TAB 34 DISPATCH 35 STRINGP 7 VECTOR 11, 30
PPRINT-TABULAR 34 SET-SYNTAX- STRUCTURE 42 VECTOR-POP 11
Fu PRESENT-SYMBOL 21 STRUCTURE-CLASS VECTOR-PUSH 11
(complex real [imag 0 ]) ⊲ Make a complex number. FROM-CHAR 32
PRESENT-SYMBOLS SETF 16, 42 30 VECTOR-
21 SETQ 16 STRUCTURE-OBJECT PUSH-EXTEND 11
Fu PRIN1 33 30
(phase number ) ⊲ Angle of number ’s polar representation. SEVENTH 8 VECTORP 10
PRIN1-TO-STRING 33 SHADOW 42 STYLE-WARNING 30
PRINC 33 SHADOWING-IMPORT SUBLIS 10
Fu PRINC-TO-STRING 33 WARN 27
(abs n) ⊲ Return |n|. 41 SUBSEQ 12
PRINT 33 SUBSETP 8 WARNING 30
SHARED-INITIALIZE
PRINT- SUBST 10 WHEN 19, 21
Fu 24
NOT-READABLE 30 SUBST-IF 10 WHILE 23
(rational real ) PRINT-
SHIFTF 16
SUBST-IF-NOT 10 WILD-PATHNAME-P
Fu SHORT-FLOAT 30, 33
(rationalize real ) NOT-READABLE- SHORT- SUBSTITUTE 13 31
OBJECT 28 SUBSTITUTE-IF 13 WITH 21
FLOAT-EPSILON 6
⊲ Convert real to rational. Assume complete/limited accu- PRINT-OBJECT 33 SHORT-FLOAT- SUBSTITUTE-IF-NOT WITH-ACCESSORS 24
WITH-COMPILATION-
racy for real . PRINT-UNREADABLE- NEGATIVE-EPSILON 13
UNIT 44
OBJECT 33 6 SUBTYPEP 29
PROBE-FILE 40 SUM 23 WITH-CONDITION-
Fu SHORT-SITE-NAME 46
(float real [prototype 0.0F0 ]) PROCLAIM 45 SIGNAL 27 SUMMING 23 RESTARTS 28
PROG 20 SVREF 11 WITH-HASH-TABLE-
⊲ Convert real into float with type of prototype. PROG1 19
SIGNED-BYTE 30
SIGNUM 4 SXHASH 14 ITERATOR 14
PROG2 19 SYMBOL 21, 30, 42 WITH-INPUT-
SIMPLE-ARRAY 30
PROG∗ 20 SYMBOL-FUNCTION FROM-STRING 39
SIMPLE-BASE-STRING
PROGN 19, 26 42 WITH-OPEN-FILE 39
30
PROGRAM-ERROR 30 SYMBOL-MACROLET WITH-OPEN-STREAM
1.3 Logic Functions PROGV 20
SIMPLE-BIT-VECTOR
30 18 39
PROVIDE 42 SYMBOL-NAME 42 WITH-OUTPUT-
SIMPLE-
TO-STRING 39
Negative integers are used in two’s complement representation. PSETF 16 BIT-VECTOR-P 10 SYMBOL-PACKAGE 42
WITH-PACKAGE-
PSETQ 16 SIMPLE-CONDITION SYMBOL-PLIST 42
PUSH 9 SYMBOL-VALUE 42 ITERATOR 42
Fu 30
WITH-SIMPLE-
(boole operation int-a int-b) PUSHNEW 9 SIMPLE-CONDITION- SYMBOLP 41
RESTART 28
FORMAT- SYMBOLS 21
⊲ Return value of bitwise logical operation . operation s are QUOTE 32, 44 ARGUMENTS 29 SYNONYM-STREAM WITH-SLOTS 24
30 WITH-STANDARD-
SIMPLE-CONDITION-
SYNONYM-STREAM- IO-SYNTAX 31
co FORMAT-CONTROL
RANDOM 4 WRITE 34
boole-1 ⊲ int-a. RANDOM-STATE 30
29 SYMBOL 38
WRITE-BYTE 34
co SIMPLE-ERROR 30
RANDOM-STATE-P 3 WRITE-CHAR 34
boole-2 ⊲ int-b. RASSOC 9
SIMPLE-STRING 30 T 2, 30, 43
WRITE-LINE 34
co SIMPLE-STRING-P 7 TAGBODY 20
WRITE-SEQUENCE 34
boole-c1 ⊲ ¬int-a. RASSOC-IF 9
RASSOC-IF-NOT 9
SIMPLE-TYPE-ERROR TAILP 8
WRITE-STRING 34
co 30 TAN 3
boole-c2 ⊲ ¬int-b. RATIO 30, 33
SIMPLE-VECTOR 30 TANH 3
WRITE-TO-STRING 34
co RATIONAL 4, 30
SIMPLE-VECTOR-P 10 TENTH 8
boole-set ⊲ All bits set. RATIONALIZE 4 SIMPLE-WARNING 30 TERPRI 33 Y-OR-N-P 31
co RATIONALP 3
SIN 3 THE 21, 29 YES-OR-NO-P 31
boole-clr ⊲ All bits zero. READ 31
SINGLE-FLOAT 30, 33 THEN 21
co READ-BYTE 31
SINGLE- THEREIS 23
boole-eqv ⊲ int-a ≡ int-b. READ-CHAR 31
FLOAT-EPSILON 6 THIRD 8
ZEROP 3

4 49
Common Lisp Quick Reference Common Lisp Quick Reference

co
DOUBLE-FLOAT- FUNCTION-LAMBDA- LEAST-NEGATIVE- MAKE-STRING- boole-and ⊲ int-a ∧ int-b.
NEGATIVE-EPSILON EXPRESSION 17 NORMALIZED- INPUT-STREAM 38 co
6 FUNCTIONP 15 SHORT-FLOAT 6 MAKE-STRING- boole-andc1 ⊲ ¬int-a ∧ int-b.
DOWNFROM 21 LEAST-NEGATIVE- OUTPUT-STREAM co
DOWNTO 21 NORMALIZED- 38 boole-andc2 ⊲ int-a ∧ ¬int-b.
GCD 3 co
DPB 5 SINGLE-FLOAT 6 MAKE-SYMBOL 42
DRIBBLE 44
GENERIC-FUNCTION
LEAST-NEGATIVE- MAKE-SYNONYM- boole-nand ⊲ ¬(int-a ∧ int-b).
30 co
DYNAMIC-EXTENT 45 SHORT-FLOAT 6 STREAM 38
GENSYM 42
LEAST-NEGATIVE- MAKE-TWO-
boole-ior ⊲ int-a ∨ int-b.
GENTEMP 42 co
SINGLE-FLOAT 6 WAY-STREAM 38 boole-orc1 ⊲ ¬int-a ∨ int-b.
GET 16
EACH 21 LEAST-POSITIVE- MAKUNBOUND 16 co
GET-DECODED-TIME
ECASE 19
46
DOUBLE-FLOAT 6 MAP 14 boole-orc2 ⊲ int-a ∨ ¬int-b.
ECHO-STREAM 30 LEAST-POSITIVE- MAP-INTO 14 co
GET-
ECHO-STREAM-
DISPATCH-MACRO-
LONG-FLOAT 6 MAPC 9 boole-xor ⊲ ¬(int-a ≡ int-b).
INPUT-STREAM 38 LEAST-POSITIVE- MAPCAN 9 co
CHARACTER 32
ECHO-STREAM-
GET-INTERNAL-
NORMALIZED- MAPCAR 9 boole-nor ⊲ ¬(int-a ∨ int-b).
OUTPUT-STREAM DOUBLE-FLOAT 6 MAPCON 9
REAL-TIME 46
38 LEAST-POSITIVE- MAPHASH 14
GET-INTERNAL- Fu
ED 44
RUN-TIME 46
NORMALIZED- MAPL 9
MAPLIST 9
(lognot integer ) ⊲ ¬integer .
EIGHTH 8 LONG-FLOAT 6
GET-MACRO-
ELSE 21 LEAST-POSITIVE- MASK-FIELD 5
CHARACTER 32 Fu
ELT 12 GET-OUTPUT-
NORMALIZED- MAX 4, 26 (logeqv integer ∗ )
ENCODE-UNIVERSAL- SHORT-FLOAT 6 MAXIMIZE 23 Fu
TIME 46
STREAM-STRING 38
GET-PROPERTIES 16
LEAST-POSITIVE- MAXIMIZING 23 (logand integer ∗ )
NORMALIZED- MEMBER 8, 29
END 21 GET-SETF-
SINGLE-FLOAT 6 MEMBER-IF 8
⊲ Return value of exclusive-nored or anded integer s, re-
END-OF-FILE 30 EXPANSION 19
ENDP 8 GET-UNIVERSAL-
LEAST-POSITIVE- MEMBER-IF-NOT 8 spectively. Without any integer , return −1.
ENOUGH- SHORT-FLOAT 6 MERGE 12
TIME 46
NAMESTRING 40 LEAST-POSITIVE- MERGE-PATHNAMES Fu
ENSURE-
GETF 16
SINGLE-FLOAT 6 40 (logandc1 int-a int-b) ⊲ ¬int-a ∧ int-b.
GETHASH 14
DIRECTORIES- LENGTH 12 METHOD 30
GO 20 Fu
EXIST 40 LET 20 METHOD-
ENSURE-GENERIC-
GRAPHIC-CHAR-P 6
LET∗ 20 COMBINATION (logandc2 int-a int-b) ⊲ int-a ∧ ¬int-b.
FUNCTION 25 LISP- 30, 42
METHOD- Fu
HANDLER-BIND 27 IMPLEMENTATION-
EQ 15
EQL 15, 29 HANDLER-CASE 27 TYPE 46 COMBINATION-
(lognand int-a int-b) ⊲ ¬(int-a ∧ int-b).
EQUAL 15 HASH-KEY 21 LISP- ERROR 25
Fu
EQUALP 15 HASH-KEYS 21
HASH-TABLE 30
IMPLEMENTATION-
VERSION 46
METHOD-
QUALIFIERS 26
(logxor integer ∗ )
ERROR 27, 30 Fu
ETYPECASE 29 HASH-TABLE-COUNT LIST 8, 26, 30 MIN 4, 26 (logior integer ∗ )
EVAL 44 14 LIST-ALL-PACKAGES MINIMIZE 23
EVAL-WHEN 43 HASH-TABLE-P 14 41 MINIMIZING 23 ⊲ Return value of exclusive-ored or ored integer s, respec-
EVENP 3 HASH-TABLE- LIST-LENGTH 8 MINUSP 3 tively. Without any integer, return 0.
EVERY 12 REHASH-SIZE 14 LIST∗ 8 MISMATCH 12
EXP 3 HASH- LISTEN 38 MOD 4, 29 Fu
EXPORT 42 TABLE-REHASH- LISTP 8 MOST-NEGATIVE- (logorc1 int-a int-b) ⊲ ¬int-a ∨ int-b.
EXPT 3 THRESHOLD 14 LOAD 43 DOUBLE-FLOAT 6
EXTENDED-CHAR 30 HASH-TABLE-SIZE 14 LOAD-LOGICAL- MOST-NEGATIVE- Fu
EXTERNAL-SYMBOL HASH-TABLE-TEST 14 PATHNAME- FIXNUM 6 (logorc2 int-a int-b) ⊲ int-a ∨ ¬int-b.
21 HASH-VALUE 21 TRANSLATIONS 40 MOST-NEGATIVE-
HASH-VALUES 21 LOAD-TIME-VALUE 44 LONG-FLOAT 6 Fu
EXTERNAL-SYMBOLS
21 HOST-NAMESTRING LOCALLY 44 MOST-NEGATIVE- (lognor int-a int-b) ⊲ ¬(int-a ∨ int-b).
40 LOG 3 SHORT-FLOAT 6
MOST-NEGATIVE- Fu
LOGAND 5
SINGLE-FLOAT 6
(logbitp i integer )
FBOUNDP 16 IDENTITY 17 LOGANDC1 5
FCEILING 4 IF 19, 21 LOGANDC2 5 MOST-POSITIVE- ⊲ T if zero-indexed ith bit of integer is set.
FDEFINITION 17 LOGBITP 5 DOUBLE-FLOAT 6
IGNORABLE 45 MOST-POSITIVE-
FFLOOR 4 LOGCOUNT 5 Fu
FIFTH 8
IGNORE 45
LOGEQV 5 FIXNUM 6 (logtest int-a int-b)
IGNORE-ERRORS 27 MOST-POSITIVE-
FILE-AUTHOR 40 IMAGPART 4 LOGICAL-PATHNAME
LONG-FLOAT 6
⊲ Return T if there is any bit set in int-a which is set in
FILE-ERROR 30 IMPORT 41 30, 40
FILE-ERROR- IN 21 LOGICAL-PATHNAME- MOST-POSITIVE- int-b as well.
PATHNAME 28 TRANSLATIONS 40 SHORT-FLOAT 6
IN-PACKAGE 41 MOST-POSITIVE- Fu
FILE-LENGTH 40 INCF 3 LOGIOR 5
SINGLE-FLOAT 6
(logcount int)
FILE-NAMESTRING 40 INITIALIZE-INSTANCE LOGNAND 5
FILE-POSITION 38 24 LOGNOR 5 MUFFLE-WARNING 28 ⊲ Number of 1 bits in int ≥ 0, number of 0 bits in int < 0.
FILE-STREAM 30 LOGNOT 5 MULTIPLE-
INITIALLY 23 VALUE-BIND 20
FILE-STRING-LENGTH INLINE 45 LOGORC1 5
LOGORC2 5 MULTIPLE-
38 INPUT-STREAM-P 31
LOGTEST 5 VALUE-CALL 17
FILE-WRITE-DATE 40
FILL 12
INSPECT 45
INTEGER 30 LOGXOR 5 MULTIPLE- 1.4 Integer Functions
LONG-FLOAT 30, 33 VALUE-LIST 17
FILL-POINTER 11 INTEGER- Fu
MULTIPLE-
FINALLY 23 DECODE-FLOAT 6 LONG-
VALUE-PROG1 19 (integer-length integer)
FIND 13 INTEGER-LENGTH 5 FLOAT-EPSILON 6
FIND-ALL-SYMBOLS INTEGERP 3 LONG-FLOAT- MULTIPLE- ⊲ Number of bits necessary to represent integer .
NEGATIVE-EPSILON VALUE-SETQ 16
41 INTERACTIVE-
6 MULTIPLE- Fu
FIND-CLASS 24 STREAM-P 31
FIND-IF 13 INTERN 41 LONG-SITE-NAME 46 VALUES-LIMIT 17 (ldb-test byte-spec integer )
FIND-IF-NOT 13 INTERNAL- LOOP 21 ⊲ Return T if any bit specified by byte-spec in integer is set.
FIND-METHOD 25 TIME-UNITS- LOOP-FINISH 23 NAME-CHAR 7
FIND-PACKAGE 41 PER-SECOND 46 LOWER-CASE-P 6 NAMED 21 Fu
FIND-RESTART 28 INTERSECTION 10 NAMESTRING 40 (ash integer count)
FIND-SYMBOL 41 INTO 23
FINISH-OUTPUT 38 INVALID-METHOD- MACHINE-INSTANCE
NBUTLAST 9 ⊲ Return copy of integer arithmetically shifted left by
NCONC 9, 23, 26
FIRST 8 ERROR 25 46 NCONCING 23 count adding zeros at the right, or, for count < 0, shifted
FIXNUM 30 INVOKE-DEBUGGER MACHINE-TYPE 46 NEVER 23
FLET 17 27 MACHINE-VERSION 46 NEWLINE 6
right discarding bits.
FLOAT 4, 30 INVOKE-RESTART 28 MACRO-FUNCTION 44 NEXT-METHOD-P 24 Fu
FLOAT-DIGITS 6 INVOKE-RESTART- MACROEXPAND 44 NIL 2, 43 (ldb byte-spec integer )
FLOAT-PRECISION 6 INTERACTIVELY 28 MACROEXPAND-1 44 NINTERSECTION 10
FLOAT-RADIX 6 ISQRT 3 MACROLET 18 NINTH 8 ⊲ Extract byte denoted by byte-spec from integer . setfable.
FLOAT-SIGN 4 IT 21, 23 MAKE-ARRAY 10 NO-APPLICABLE-
FLOATING- MAKE-BROADCAST- METHOD 25  Fu ff
POINT-INEXACT 30 STREAM 38 NO-NEXT-METHOD deposit-field
KEYWORD 30, 41, 43 ( Fu int-a byte-spec int-b)
FLOATING-
POINT-INVALID-
KEYWORDP 41
MAKE-
CONCATENATED-
25 dpb
NOT 15, 29, 33
OPERATION 30 STREAM 38 NOTANY 12 ⊲ Return int-b with bits denoted by byte-spec replaced
FLOATING-POINT- MAKE-CONDITION 27 Fu
LABELS 17 NOTEVERY 12
OVERFLOW 30 LAMBDA 17 MAKE- NOTINLINE 45
by corresponding bits of int-a, or by the low (byte-size
FLOATING-POINT- LAMBDA-LIST- DISPATCH-MACRO- NRECONC 9 byte-spec) bits of int-a, respectively.
UNDERFLOW 30 KEYWORDS 19 CHARACTER 32 NREVERSE 12
FLOATP 3 LAMBDA- MAKE- NSET-DIFFERENCE 10 Fu
FLOOR 4 PARAMETERS- ECHO-STREAM 38 NSET-EXCLUSIVE-OR (mask-field byte-spec integer)
FMAKUNBOUND 17 MAKE-HASH-TABLE
FOR 21
LIMIT 17
LAST 8 14
10
NSTRING-CAPITALIZE
⊲ Return copy of integer with all bits unset but those de-
FORCE-OUTPUT 38 LCM 3 MAKE-INSTANCE 24 7 noted by byte-spec. setfable.
FORMAT 35 LDB 5 MAKE-INSTANCES- NSTRING-DOWNCASE
FORMATTER 35 LDB-TEST 5 OBSOLETE 24 7 Fu
FOURTH 8 LDIFF 9 MAKE-LIST 8 NSTRING-UPCASE 7 (byte size position )
FRESH-LINE 33 LEAST-NEGATIVE- MAKE-LOAD-FORM 44 NSUBLIS 10 ⊲ Byte specifier for a byte of size bits starting at a weight
FROM 21 DOUBLE-FLOAT 6 MAKE-LOAD-FORM- NSUBST 10
FROUND 4 LEAST-NEGATIVE- SAVING-SLOTS 44 NSUBST-IF 10 of 2position .
FTRUNCATE 4 LONG-FLOAT 6 MAKE-METHOD 26 NSUBST-IF-NOT 10
Fu
FTYPE 45 LEAST-NEGATIVE- MAKE-PACKAGE 41 NSUBSTITUTE 13 (byte-size byte-spec)
FUNCALL 17 NORMALIZED- MAKE-PATHNAME 39 NSUBSTITUTE-IF 13 Fu
FUNCTION DOUBLE-FLOAT 6 MAKE- NSUBSTITUTE- (byte-position byte-spec)
17, 30, 33, 42 LEAST-NEGATIVE- RANDOM-STATE 4 IF-NOT 13
FUNCTION- NORMALIZED- MAKE-SEQUENCE 12 NTH 8
⊲ Size or position, respectively, of byte-spec.
KEYWORDS 26 LONG-FLOAT 6 MAKE-STRING 7 NTH-VALUE 17

48 5
Common Lisp Quick Reference Common Lisp Quick Reference

1.5 Implementation-Dependent Index


co 9
short-float >>
co = ” 32 &ALLOW- BIGNUM 30 COMPILE-FILE-
single-float epsilon ’ 32 OTHER-KEYS 19 BIT 11, 30 PATHNAME 43
co -
double-float>> negative-epsilon ( 32 &AUX 19 BIT-AND 11 COMPILED-
co ; () 43 &BODY 19 BIT-ANDC1 11 FUNCTION 30
long-float ) 32 &ENVIRONMENT 19 BIT-ANDC2 11 COMPILED-
∗ 3, 29, 30, 40, 44 &KEY 19 BIT-EQV 11 FUNCTION-P 43
⊲ Smallest possible number making a difference when ∗∗ 40, 44 &OPTIONAL 19 BIT-IOR 11 COMPILER-MACRO 42
added or subtracted, respectively. ∗∗∗ 44 &REST 19 BIT-NAND 11 COMPILER-MACRO-
∗BREAK- &WHOLE 19 BIT-NOR 11 FUNCTION 44
co 98 ON-SIGNALS∗ 29 ∼( ∼) 36 BIT-NOT 11 COMPLEMENT 17
least-negative >
> >short-float
=>
∗COMPILE-FILE- ∼∗ 37 BIT-ORC1 11 COMPLEX 4, 30, 33
co < PATHNAME∗ 43 ∼/ / 37 BIT-ORC2 11 COMPLEXP 3
least-negative-normalized single-float
co - ∗COMPILE-FILE- ∼< ∼:> 37 BIT-VECTOR 30 COMPUTE-
least-positive >
> >double-float TRUENAME∗ 43 ∼< ∼> 36 BIT-VECTOR-P 10 APPLICABLE-
co ;> : ∗COMPILE-PRINT∗ 43 ∼? 37 BIT-XOR 11 METHODS 25
least-positive-normalized long-float ∗COMPILE- ∼A 36 BLOCK 20 COMPUTE-RESTARTS
⊲ Available numbers closest to −0 or +0, respectively. VERBOSE∗ 43 ∼B 36 BOOLE 4 28
∗DEBUG-IO∗ 39 ∼C 36 BOOLE-1 4 CONCATENATE 12
8 ∗DEBUGGER-HOOK∗ ∼D 36 BOOLE-2 4 CONCATENATED-
>short-float 29 ∼E 36 BOOLE-AND 5 STREAM 30
co ff>>
<single-float ∗DEFAULT- ∼F 36
∼G 36
BOOLE-ANDC1 5 CONCATENATED-
STREAM-STREAMS
most-negative PATHNAME- BOOLE-ANDC2 5
co - double-float DEFAULTS∗ 40 ∼I 37 BOOLE-C1 4 38
most-positive >>long-float ∗ERROR-OUTPUT∗ 39 ∼O 36 BOOLE-C2 4 COND 19
>
: ∗FEATURES∗ 33 ∼P 36 BOOLE-CLR 4 CONDITION 30
∼R 36
fixnum ∗GENSYM-
∼S 36
BOOLE-EQV 4 CONJUGATE 4
COUNTER∗ 42 BOOLE-IOR 5 CONS 8, 30
⊲ Available numbers closest to −∞ or +∞, respectively. ∗LOAD-PATHNAME∗ ∼T 37 BOOLE-NAND 5 CONSP 8
43 ∼W 37 BOOLE-NOR 5 CONSTANTLY 17
Fu ∗LOAD-PRINT∗ 43 ∼X 36 BOOLE-ORC1 5 CONSTANTP 15
(decode-float n) ∗LOAD-TRUENAME∗ ∼[ ∼] 37 BOOLE-ORC2 5 CONTINUE 28
Fu ∼$ 36
(integer-decode-float n) 43
∼% 36
BOOLE-SET 4 CONTROL-ERROR 30
∗LOAD-VERBOSE∗ 43 BOOLE-XOR 5 COPY-ALIST 9
⊲ Return significand, exponent, and sign of float n. ∗MACROEXPAND- ∼& 36 BOOLEAN 30 COPY-LIST 9
2 3 HOOK∗ 44 ∼ˆ 37 BOTH-CASE-P 6 COPY-PPRINT-
∗MODULES∗ 42 ∼ 36 BOUNDP 15 DISPATCH 35
Fu
(scale-float n [i ]) ⊲ With n’s radix b, return nbi . ∗PACKAGE∗ 41 ∼| 36
∼{ ∼} 37
BREAK 45 COPY-READTABLE 32
∗PRINT-ARRAY∗ 35 BROADCAST- COPY-SEQ 14
∗PRINT-BASE∗ 35 ∼∼ 36 STREAM 30 COPY-STRUCTURE 15
Fu
(float-radix n) ∗PRINT-CASE∗ 35 ∼←֓ 36
` 32
BROADCAST- COPY-SYMBOL 42
Fu ∗PRINT-CIRCLE∗ 35 STREAM-STREAMS COPY-TREE 10
(float-digits n) ∗PRINT-ESCAPE∗ 35 | | 33 38 COS 3
Fu 1+ 3
(float-precision n) ∗PRINT-GENSYM∗ 35
1– 3
BUILT-IN-CLASS 30 COSH 3
∗PRINT-LENGTH∗ 35 BUTLAST 9 COUNT 12, 23
⊲ Radix, number of digits in that radix, or precision in that ∗PRINT-LEVEL∗ 35 BY 21 COUNT-IF 12
radix, respectively, of float n. ∗PRINT-LINES∗ 35 ABORT 28 BYTE 5 COUNT-IF-NOT 12
∗PRINT- ABOVE 21 BYTE-POSITION 5 COUNTING 23
Fu MISER-WIDTH∗ 35 ABS 4 BYTE-SIZE 5 CTYPECASE 29
(upgraded-complex-part-type foo [environment NIL ]) ∗PRINT-PPRINT- ACONS 9
DISPATCH∗ 35
⊲ Type of most specialized complex number able to hold ∗PRINT-PRETTY∗ 35
ACOS 3
ACOSH 4 CAAR 8 DEBUG 45
parts of type foo. ∗PRINT-RADIX∗ 35 ACROSS 21 CADR 8 DECF 3
∗PRINT-READABLY∗ ADD-METHOD 25 CALL-ARGUMENTS- DECLAIM 45
35 ADJOIN 9 LIMIT 17 DECLARATION 45
∗PRINT-RIGHT- ADJUST-ARRAY 10 CALL-METHOD 26 DECLARE 45
MARGIN∗ 35 ADJUSTABLE- CALL-NEXT-METHOD DECODE-FLOAT 6
2 Characters ∗QUERY-IO∗ 39
∗RANDOM-STATE∗ 4
ARRAY-P 10
ALLOCATE-INSTANCE
25
CAR 8
DECODE-UNIVERSAL-
TIME 46
∗READ-BASE∗ 32 24 CASE 19 DEFCLASS 23
∗READ-DEFAULT- ALPHA-CHAR-P 6 CATCH 20 DEFCONSTANT 16
The standard-char type comprises a-z, A-Z, 0-9, Newline, Space, and FLOAT-FORMAT∗ ALPHANUMERICP 6 CCASE 19 DEFGENERIC 24
32 ALWAYS 23 CDAR 8 DEFINE-COMPILER-
!?$"’‘.:,;*+-/|\~ ^<=>#%@&()[]{}. ∗READ-EVAL∗ 33 AND 19, 21, 26, 29, 33 CDDR 8 MACRO 18
∗READ-SUPPRESS∗ 32 APPEND 9, 23, 26 CDR 8 DEFINE-CONDITION
Fu ∗READTABLE∗ 32 APPENDING 23
(characterp foo) CEILING 4 27
Fu ⊲ T if argument is of indicated type. ∗STANDARD-INPUT∗ APPLY 17 CELL-ERROR 30 DEFINE-METHOD-
(standard-char-p char ) 39 APROPOS 44 CELL-ERROR-NAME COMBINATION 26
∗STANDARD- APROPOS-LIST 44 28 DEFINE-MODIFY-
Fu OUTPUT∗ 39 AREF 10 CERROR 27 MACRO 19
(graphic-char-p character ) ∗TERMINAL-IO∗ 39 ARITHMETIC-ERROR CHANGE-CLASS 24 DEFINE-SETF-
Fu ∗TRACE-OUTPUT∗ 45 30 CHAR 8 EXPANDER 18
(alpha-char-p character ) + 3, 26, 44 ARITHMETIC-ERROR- CHAR-CODE 7 DEFINE-SYMBOL-
Fu
(alphanumericp character ) ++ 44 OPERANDS 28
ARITHMETIC-ERROR-
CHAR-CODE-LIMIT 7 MACRO 18
+++ 44 CHAR-DOWNCASE 7 DEFMACRO 18
⊲ T if character is visible, alphabetic, or alphanumeric, re- , 32 OPERATION 28 CHAR-EQUAL 6 DEFMETHOD 25
ARRAY 30
spectively. ,. 32
,@ 32 ARRAY-DIMENSION 11
CHAR-GREATERP 7 DEFPACKAGE 41
CHAR-INT 7 DEFPARAMETER 16
– 3, 44 ARRAY-DIMENSION- CHAR-LESSP 7 DEFSETF 18
Fu
(upper-case-p character ) . 32 LIMIT 11 CHAR-NAME 7 DEFSTRUCT 15
Fu / 3, 33, 44 ARRAY-DIMENSIONS CHAR-NOT-EQUAL 6 DEFTYPE 29
(lower-case-p character ) // 44 11 CHAR- DEFUN 17
Fu ARRAY-
(both-case-p character ) /// 44
DISPLACEMENT 11
NOT-GREATERP 7 DEFVAR 16
/= 3 CHAR-NOT-LESSP 7 DELETE 13
⊲ Return T if character is uppercase, lowercase, or able to : 41 ARRAY- CHAR-UPCASE 7 DELETE-DUPLICATES
:: 41 ELEMENT-TYPE 29
be in another case, respectively. :ALLOW- ARRAY-HAS-
CHAR/= 6 13
CHAR< 6 DELETE-FILE 40
OTHER-KEYS 19 FILL-POINTER-P 10 CHAR<= 6 DELETE-IF 13
Fu
(digit-char-p character [radix 10 ]) ; 32 ARRAY-IN-BOUNDS-P
10
CHAR= 6 DELETE-IF-NOT 13
< 3 CHAR> 6 DELETE-PACKAGE 41
⊲ Return its weight if character is a digit, or NIL otherwise. <= 3 ARRAY-RANK 11 CHAR>= 6 DENOMINATOR 4
= 3, 21 ARRAY-RANK-LIMIT CHARACTER 7, 30, 32 DEPOSIT-FIELD 5
Fu > 3 11
(char= character + ) >= 3 ARRAY-ROW-
CHARACTERP 6
CHECK-TYPE 29
DESCRIBE 45
DESCRIBE-OBJECT 45
Fu
(char/= character + ) \ 33 MAJOR-INDEX 11
ARRAY-TOTAL-SIZE
CIS 4 DESTRUCTURING-
# 37 CL 43 BIND 20
⊲ Return T if all character s, or none, respectively, are equal. #\ 32 11
CL-USER 43 DIGIT-CHAR 7
#’ 33 ARRAY-TOTAL-
CLASS 30 DIGIT-CHAR-P 6
Fu #( 33 SIZE-LIMIT 11
CLASS-NAME 24 DIRECTORY 40
(char-equal character + ) #∗ 33
ARRAYP 10
CLASS-OF 24 DIRECTORY-
Fu AS 21
(char-not-equal character + ) #+ 33
ASH 5
CLEAR-INPUT 38 NAMESTRING 40
#– 33 CLEAR-OUTPUT 38 DISASSEMBLE 45
⊲ Return T if all character s, or none, respectively, are equal #. 33
ASIN 3
CLOSE 39 DIVISION-BY-ZERO 30
ASINH 4
ignoring case. #: 33
ASSERT 27
CLQR 1 DO 20, 21
#< 33 CLRHASH 14 DO-ALL-SYMBOLS 42
ASSOC 9
Fu #= 33 CODE-CHAR 7 DO-EXTERNAL-
ASSOC-IF 9
(char> character + ) #A 33
ASSOC-IF-NOT 9
COERCE 29 SYMBOLS 42
Fu #B 32 COLLECT 23 DO-SYMBOLS 42
(char>= character + ) #C( 33
ATAN 3
COLLECTING 23 DO∗ 20
Fu ATANH 4
(char< character + ) #O 32
ATOM 8, 30 COMMON-LISP 43 DOCUMENTATION 42
Fu #P 33 COMMON-LISP-USER DOING 21
(char<= character + ) #R 32 43 DOLIST 21
⊲ Return T if character s are monotonically decreasing, #S( 33 BASE-CHAR 30 COMPILATION-SPEED DOTIMES 20
#X 32 BASE-STRING 30 45 DOUBLE-FLOAT 30, 33
monotonically non-increasing, monotonically increasing, or ## 33 BEING 21 COMPILE 43 DOUBLE-
#| |# 32 BELOW 21 COMPILE-FILE 43 FLOAT-EPSILON 6
monotonically non-decreasing, respectively.

6 47
Common Lisp Quick Reference Common Lisp Quick Reference
Fu
(char-greaterp character + )
16 External Environment Fu
(char-not-lessp character + )
Fu
Fu (char-lessp character + )
Fu
(get-internal-real-time) (char-not-greaterp character + )
Fu
(get-internal-run-time) ⊲ Return T if character s are monotonically decreasing,
⊲ Current time, or computing time, respectively, in clock monotonically non-increasing, monotonically increasing, or
ticks. monotonically non-decreasing, respectively, ignoring case.
co
internal-time-units-per-second Fu
(char-upcase character )
⊲ Number of clock ticks per second. Fu
(char-downcase character )
Fu ⊲ Return corresponding uppercase/lowercase character, re-
(encode-universal-time sec min hour date month year [zone curr ])
Fu spectively.
(get-universal-time)
⊲ Seconds from 1900-01-01, 00:00, ignoring leap seconds. Fu
(digit-char i [radix 10 ]) ⊲ Character representing digit i.
Fu
(decode-universal-time universal-time [time-zone current ]) Fu
Fu (char-name character ) ⊲ character ’s name if any, or NIL.
(get-decoded-time)
Fu
⊲ Return second, minute, hour, date, month, year, day, (name-char foo) ⊲ Character named foo if any, or NIL.
2 3 4 5 6 7
daylight-p, and zone. Fu
8 9 (char-int character )
Fu ⊲ Code of character .
Fu (char-code character )
(room [{NIL :default T}])
⊲ Print information about internal storage management. Fu
(code-char code) ⊲ Character with code.
Fu
(short-site-name) co
char-code-limit
Fu
⊲ Upper bound of (char-code char ); ≥ 96.
Fu
(long-site-name)
Fu
⊲ String representing physical location of computer. (character c) ⊲ Return #\c.
8 Fu 9
<lisp-implementation = ff
Fu type
( software - )
: Fu ; version
machine 3 Strings
⊲ Name or version of implementation, operating system, or
hardware, respectively. Strings can as well be manipulated by array and sequence functions;
Fu see pages 10 and 12.
(machine-instance) ⊲ Computer name.
Fu
(stringp foo)
Fu ⊲ T if foo is of indicated type.
(simple-string-p foo)
8˛ 9
> ˛:start1 start-foo 0 >
 Fu ff >
<˛˛ >
=
string= :start2 start-bar 0
( Fu foo bar ˛˛ )
string-equal >
> :end1 end-foo NIL >
:˛˛ >
;
:end2 end-bar NIL
⊲ Return T if subsequences of foo and bar are equal.
Obey/ignore, respectively, case.
8 Fu 9
>string{/= -not-equal} > 8˛ 9
> Fu
> >
> > ˛:start1 start-foo 0 >
>
<string{> -greaterp} >
= <˛˛
> >
=
Fu :start2 start-bar 0
( string{>= -not-lessp} foo bar ˛˛ )
>
> >
> >
> :end1 end-foo >
:˛˛ >
Fu NIL
>
>string{< -lessp} >
> ;
: Fu ; :end2 end-bar NIL
string{<= -not-greaterp}
⊲ If foo is lexicographically not equal, greater, not less,
less, or not greater, respectively, then return position of
first mismatching character in foo. Otherwise return NIL.
Obey/ignore, respectively, case.
˛ ff
Fu ˛:initial-element char
(make-string size ˛˛ )
:element-type type character
⊲ Return string of length size.
Fu
(8
string x ) 9
Fu
<string-capitalize = ˛˛ ff
Fu :start start 0
( string-upcase x ˛˛ )
: Fu ; :end end NIL
string-downcase
⊲ Convert x (symbol, string, or character) into a string, a
string with capitalized words, an all-uppercase string, or an
all-lowercase string, respectively.
8 Fu 9
<nstring-capitalize = ˛ ff
˛
Fu
( nstring-upcase ^ ˛:start start 0 )
string
: Fu ; ˛:end end NIL
nstring-downcase
⊲ Convert string into a string with capitalized words, an
all-uppercase string, or an all-lowercase string, respectively.
8 Fu 9
<string-trim
Fu
=
( string-left-trim char-bag string)
: Fu ;
string-right-trim
⊲ Return string with all characters in sequence char-bag
removed from both ends, from the beginning, or from the
end, respectively.

46 7
Common Lisp Quick Reference Common Lisp Quick Reference
Fu  ff∗
(char string i ) M function
Fu (untrace )
(schar string i ) (setf function)
⊲ Return zero-indexed ith character of string ignor- ⊲ Stop functions, or each currently traced function, from
ing/obeying, respectively, fill pointer. setfable. being traced.
8˛ 9
> ˛:start start 0 >
var
∗trace-output∗
>
<˛˛ >
= M M
Fu
˛ :end end NIL ⊲ Stream trace and time print their output on.
(parse-integer string ˛ )
>
> :radix int >
:˛˛ 10 >
;
:junk-allowed bool NIL M
(step form )
⊲ Return integer parsed from string and index of parse end. ⊲ Step through evaluation of form. Return values of form .
2

Fu
(break [control arg ∗ ])
⊲ Jump directly into debugger; return NIL. See p. 35,
4 Conses Fu
format, for control and arg s.

4.1 Predicates M
(time form)
Fu ⊲ Evaluate forms and print timing information to
(consp foo) var
Fu ⊲ Return T if foo is of indicated type. ∗trace-output∗. Return values of form .
(listp foo)
Fu Fu
(endp list) (inspect foo) ⊲ Interactively give information about foo.
Fu ⊲ Return T if list/foo is NIL.
(null foo)
Fu
Fu
^ ∗standard-output∗
(describe foo [stream var ])
(atom foo) ⊲ Return T if foo is not a cons. ⊲ Send information about foo to stream.
Fu
(tailp foo list) ⊲ Return T if foo is a tail of list. gF
^
(describe-object foo [stream])
8˛ 9
<˛˛ :test function #’eql = ⊲ Send information about foo to stream. Not to be called
Fu
(member foo list ˛˛ :test-not function ) by user.
:˛ ;
:key function Fu
⊲ Return tail of list starting with its first element matching (disassemble function)
foo. Return NIL if there is no such element. ⊲ Send disassembled representation of function to
var
 Fu ff ∗standard-output∗. Return NIL.
member-if
( Fu test list [:key function])
member-if-not
⊲ Return tail of list starting with its first element satisfying
test. Return NIL if there is no such element. 15.4 Declarations
8˛ 9 Fu
<˛˛ :test function #’eql = (proclaim decl )
M
Fu
(subsetp list-a list-b ˛˛ :test-not function ) d ∗)
(declaim decl
:˛ ; ⊲ Globally make declaration(s) decl . decl can be:
:key function
⊲ Return T if list-a is a subset of list-b. declaration, type, ftype, inline, notinline, optimize, or
special. See below.

4.2 Lists d ∗)
(declare decl
Fu ⊲ Inside certain forms, locally make declarations decl ∗ .
(cons foo bar ) ⊲ Return new cons (foo . bar ). decl can be: dynamic-extent, type, ftype, ignorable, ignore,
Fu inline, notinline, optimize, or special. See below.
(list foo ∗ ) ⊲ Return list of foos.
Fu
(list∗ foo + ) (declaration foo∗ )
⊲ Return list of foo s with last foo becoming cdr of last cons. ⊲ Make foos names of declarations.
Return foo if only one foo given. sO
(dynamic-extent variable ∗ (function function)∗ )
Fu ⊲ Declare lifetime of variables and/or functions to end
(make-list num [:initial-element foo NIL ])
when control leaves enclosing block.
⊲ New list with num elements set to foo.
([type] type variable ∗ )
Fu
(list-length list) ⊲ Length of list; NIL for circular list. (ftype type function ∗ )
⊲ Declare variables or functions to be of type.
Fu
(car list) ⊲ Car of list or NIL if list is NIL. setfable.  ff ff∗
ignorable var
( sO )
Fu ignore (function function)
(cdr list)
Fu ⊲ Cdr of list or NIL if list is NIL. setfable. ⊲ Suppress warnings about used/unused bindings.
(rest list)
(inline function ∗ )
Fu Fu
(nthcdr n list) ⊲ Return tail of list after calling cdr n times. (notinline function ∗ )
⊲ Tell compiler to integrate/not to integrate, respec-
Fu Fu Fu Fu Fu Fu Fu Fu
({first second third fourth fifth sixth . . . ninth tenth} list ) tively, called functions into the calling routine.
⊲ Return nth element of list if any, or NIL otherwise. 8˛ 9
> ˛compilation-speed (compilation-speed n 3 )>
setfable. >
> ˛ >
>
>
<˛˛debug (debug n 3 ) >
=
Fu ˛
(optimize ˛safety (safety n 3 ) )
(nth n list) ⊲ Zero-indexed nth element of list. setfable. > >
>
> ˛ >
>
>˛space (space n 3 )
: >
;
Fu
(cX r list ) ˛speed (speed n )
Fu 3
⊲ With X being one to four as and ds representing cars ⊲ Tell compiler how to optimize. n = 0 means unim-
Fu Fu Fu Fu
and cdrs, e.g. (cadr bar ) is equivalent to (car (cdr bar )). portant, n = 1 is neutral, n = 3 means important.
setfable. (special var ∗ ) ⊲ Declare var s to be dynamic.
Fu
(last list [num 1 ]) ⊲ Return list of last num conses of list.

8 45
Common Lisp Quick Reference Common Lisp Quick Reference

sO
 Fu ff
d ∗ )∗ form ∗ )
(locally (declare decl
P butlast list
( Fu f [num 1 ]) ⊲ list excluding last num conses.
⊲ Evaluate forms in a lexical environment with declarations nbutlast list
decl in effect. Return values of form s.  Fu ff
rplaca
M P∗
(with-compilation-unit ([:override bool NIL ]) form ) ( Fu g object)
cons
rplacd
⊲ Return values of form s. Warnings deferred by the com- ⊲ Replace car, or cdr, respectively, of cons with object.
piler until end of compilation are deferred until the end of
Fu
evaluation of forms. (ldiff list foo)
⊲ If foo is a tail of list, return preceding part of list . Oth-
sO
\ NIL ])
(load-time-value form [read-only erwise return list .
⊲ Evaluate form at compile time and treat its value as lit-
8˛ 9
eral at run time. <˛˛ :test function #’eql =
Fu
sO (adjoin foo list ˛˛ :test-not function )
c
(quote foo) ⊲ Return unevaluated foo. :˛ ;
:key function
gF ⊲ Return list if foo is already member of list. If not, return
(make-load-form foo [environment ]) Fu
(cons foo list ).
⊲ Its methods are to return a creation form which on eval-
Fu
uation at load time returns an object equivalent to foo, and M
]
(pop place)
Fu Fu
⊲ Set place to (cdr place ), return (car place ).
an optional initialization form which on evaluation performs
2
some initialization of the object. M
]
(push foo place)
Fu
⊲ Set place to (cons foo place ).
˛ ff
Fu ˛:slot-names slots
(make-load-form-saving-slots foo ˛˛ all local slots ) 8˛ 9
:environment environment <˛˛ :test function #’eql =
⊲ Return a creation form and an initialization form which
M
]
(pushnew foo place ˛ :test-not function )
2 :˛˛ ;
on evaluation construct an object equivalent to foo with :key function
Fu
slots initialized with the corresponding values from foo. ⊲ Set place to (adjoin foo place ).
Fu Fu
(macro-function symbol [environment])
 ff (append [list ∗ foo])
Fu
Fu name f ∗ foo])
(nconc [list
(compiler-macro-function [environment])
(setf name) ⊲ Return concatenated list. foo can be of any type.
⊲ Return specified macro function, or compiler macro func-
Fu
tion, respectively, if any. Return NIL otherwise. setfable. (revappend list foo)
Fu
Fu f foo)
(nreconc list
(eval arg)
⊲ Return concatenated list after reversing order in list.
⊲ Return values of value of arg evaluated in global environ-
ment.  Fu ff
mapcar
( Fu function list + )
maplist
⊲ Return list of return values of function successively in-
15.3 REPL and Debugging voked with corresponding arguments, either cars or cdrs,
var var
+ ++ +++
var respectively, from each list .
var var var
∗ ∗∗ ∗∗∗  Fu ff
mapcan
var var
/ // ///
var
( Fu function list + )
mapcon
⊲ Last, penultimate, or antepenultimate form evaluated ⊲ Return list of concatenated return values of function suc-
in the REPL, or their respective primary value, or a list of cessively invoked with corresponding arguments, either cars
their respective values. or cdrs, respectively, from each list. function should return
var a list.
– ⊲ Form currently being evaluated by the REPL.
 Fu ff
Fu mapc
(apropos string [package NIL ]) ( Fu function list + )
mapl
⊲ Print interned symbols containing string. ⊲ Return first list after successively applying function to
Fu corresponding arguments, either cars or cdrs, respectively,
(apropos-list string [package NIL ]) from each list. function should have some side effects.
⊲ List of interned symbols containing string.
Fu
Fu (copy-list list) ⊲ Return copy of list with shared elements.
(dribble [path])
⊲ Save a record of interactive session to file at path. With-
out path, close that file.
Fu
4.3 Association Lists
(ed [file-or-function NIL ]) ⊲ Invoke editor if possible. Fu
(pairlis keys values [alist NIL ])
 Fu ff
macroexpand-1 ⊲ Prepend to alist an association list made from lists keys
( Fu form [environment NIL ]) and values.
macroexpand
⊲ Return macro expansion, once or entirely, respectively, Fu
of form and T if form was a macro form. Return form and (acons key value alist )
2 ⊲ Return alist with a (key . value) pair added.
NIL otherwise.
2 8˛ 9
var  Fu ff <˛˛ :test test #’eql =
∗macroexpand-hook∗ assoc
( Fu foo alist ˛˛ :test-not test )
⊲ Function of arguments expansion function, macro form, rassoc :˛ ;
Fu
 Fu ff :key function
and environment called by macroexpand-1 to generate
assoc-if[-not]
macro expansions. ( Fu test alist [:key function])
rassoc-if[-not]
 ff∗ ⊲ First cons whose car, or cdr, respectively, satisfies test.
M function
(trace )
(setf function) Fu
(copy-alist alist) ⊲ Return copy of alist.
⊲ Cause functions to be traced. With no arguments, return
list of traced functions.

44 9
Common Lisp Quick Reference Common Lisp Quick Reference

co
4.4 Trees t
 ff ⊲ Truth; the supertype of every type including t; the su-
Fu :test test #’eql var
perclass of every class except t; ∗terminal-io∗.
(tree-equal foo bar )
:test-not test co co
⊲ Return T if trees foo and bar have same shape and leaves nil ()
satisfying test. ⊲ Falsity; the empty list; the empty type, subtype of ev-
var var
8˛ 9 ery type; ∗standard-input∗; ∗standard-output∗; the global
 Fu ff <˛ :test function #’eql = environment.
subst new old tree ˛
( Fu ˛
g :˛˛ :test-not function ;)
nsubst new old tree
:key function
⊲ Make copy of tree with each subtree or leaf matching old 14.4 Standard Packages
replaced by new .
common-lisp cl
 Fu ff ⊲ Exports the defined names of Common Lisp except for
subst-if[-not] new test tree
( Fu g [:key function]) those in the keyword package.
nsubst-if[-not] new test tree
⊲ Make copy of tree with each subtree or leaf satisfying test common-lisp-user cl-user
replaced by new . ⊲ Current package after startup; uses package common-lisp.
8˛ 9
 Fu ff <˛ :test function #’eql = keyword
sublis association-list tree ˛
( Fu ˛ ⊲ Contains symbols which are defined to be of type
g :˛˛ :test-not function ;)
nsublis association-list tree
:key function keyword.
⊲ Make copy of tree with each subtree or leaf matching a
key in association-list replaced by that key’s value.
Fu
(copy-tree tree) ⊲ Copy of tree with same shape and leaves.
15 Compiler
15.1 Predicates
Fu
4.5 Sets (special-operator-p foo) ⊲ T if foo is a special operator.
8 Fu 9 9 Fu
>intersection > > > (compiled-function-p foo)
> Fu
> = >
>
>
>set-difference >
> ⊲ T if foo is of type compiled-function.
> Fu
>union a b >
> 8˛ 9
>
> >
> >
>
< Fu ; = <˛˛ :test function #’eql =
set-exclusive-orff ˛
( Fu :test-not function )
>
>nintersection > :˛˛ ; 15.2 Compilation
>
> Fu eb >
a >
> :key function
>
>nset-difference ff >
> 8 9
> Fu > <NIL =
>
:nunion
> >
>  definitionff
Fu ee
a b; Fu
(compile name )
nset-exclusive-or : [definition];
⊲ Return a ∩ b, a \ b, a ∪ b, or a △ b, respectively, of lists a (setf name)
and b. ⊲ Return compiled function or replace name’s function def-
inition with the compiled function. Return T in case of
2
warnings or errors, and T in case of warnings or errors ex-
3
cluding style warnings.
5 Arrays 8˛ 9
> ˛:output-file out-path >
>
<˛˛:verbose bool var >
=
5.1 Predicates Fu
(compile-file file ˛˛ ∗compile-verbose∗
)
>
> :print bool var >
Fu
(arrayp foo) :˛˛ ∗compile-print∗ >
;
Fu :external-format file-format :default
(vectorp foo) ⊲ Write compiled contents of file to out-path. Return true
Fu
(simple-vector-p foo) ⊲ T if foo is of indicated type. output path or NIL, T in case of warnings or errors, T in case
Fu
(bit-vector-p foo) 2
of warnings or errors excluding style warnings.
3
Fu
(simple-bit-vector-p foo)
Fu
(compile-file-pathname file [:output-file path] [other-keyargs])
Fu Fu
(adjustable-array-p array ) ⊲ Pathname compile-file writes to if invoked with the same
Fu
(array-has-fill-pointer-p array) arguments.
⊲ T if array is adjustable/has a fill pointer, respectively. 8˛ 9
> ˛:verbose bool var >
Fu
>
<˛˛:print bool var∗load-verbose∗ >
=
(array-in-bounds-p array [subscripts]) Fu
(load path ˛ ˛ ∗load-print∗
)
⊲ Return T if subscripts are in array ’s bounds. >
> :if-does-not-exist bool >
:˛˛ T >
;
:external-format file-format :default
⊲ Load source file or compiled file into Lisp environment.
Return T if successful.
5.2 Array Functions ff
var
 Fu ˆ ˜ff ∗compile-file pathname∗ NIL
make-array dimension-sizes :adjustable bool NIL var -
( Fu ∗load truename∗ NIL
] dimension-sizes
adjust-array array Fu Fu
8˛ 9 ⊲ Input file used by compile-file/by load.
> ˛:element-type type T >
>
> ˛ >
> ff
<˛˛:fill-pointer
> {num bool } NIL >
=
var
∗compile print∗
8 -
˛<:initial-element obj ) var
∗load verbose∗
> ˛ >
>
> ˛ :initial-contents sequence >
> Fu
⊲ Defaults used by compile-file/by load.
Fu
:˛˛:
> >
;
:displaced-to array NIL [:displaced-index-offset i 0 ] 8˛ 9
⊲ Return fresh, or readjust, respectively, vector or array. <˛˛{:compile-toplevel compile}=
sO P
ˆ ˜ (eval-when ( ˛˛{:load-toplevel load} ) form ∗ )
Fu
(aref array subscripts ) :˛ ;
{:execute eval}
sO
⊲ Return array element pointed to by subscripts. setfable. ⊲ Return values of form s if eval-when is in the top-level of a
Fu file being compiled, in the top-level of a compiled file being
(row-major-aref array i) loaded, or anywhere, respectively. Return NIL if forms are
⊲ Return ith element of array in row-major order. setfable. not evaluated. (compile, load and eval deprecated.)

10 43
Common Lisp Quick Reference Common Lisp Quick Reference

Fu Fu
(shadow symbols [package ∗package∗
var ]) (array-row-major-index array [subscripts])
⊲ Make symbols of package shadow any otherwise accessi- ⊲ Index in row-major order of the element denoted by
ble, equally named symbols from other packages. Return subscripts.
T. Fu
(array-dimensions array )
Fu
(package-shadowing-symbols package) ⊲ List containing the lengths of array ’s dimensions.
⊲ List of symbols of package that shadow any otherwise
Fu
accessible, equally named symbols from other packages. (array-dimension array i)
Fu
⊲ Length of i th dimension of array .
(export symbols [package ∗package∗
var ])
Fu
⊲ Make symbols external to package. Return T. (array-total-size array ) ⊲ Number of elements in array .
Fu
(unexport symbols [package ∗package∗
var ]) Fu
(array-rank array ) ⊲ Number of dimensions of array .
⊲ Revert symbols to internal status. Return T.
Fu
8M ff 9 (array-displacement array ) ⊲ Target array and offset.
<do-symbols ˆ ˜= 2
M (d
var package ∗package∗
var [result NIL ] )
( do-external-symbols Fu
:M ; (bit bit-array [subscripts])
do-all-symbols (var [result NIL ]) Fu
˛ ff (sbit simple-bit-array [subscripts])
˛c
d ∗ )∗ ˛tag
(declare decl ∗ ⊲ Return element of bit-array or of simple-bit-array. setf-
˛form )
sO able.
⊲ Evaluate tagbody-like body with var successively bound
to every symbol from package, to every external symbol Fu
^ [result-bit-array
^
(bit-not bit-array NIL ])
from package, or to every symbol from all registered pack-
⊲ Return result of bitwise negation of bit-array. If
ages, respectively. Return values of result . Implicitly, the
sO result-bit-array is T, put result in bit-array; if it is NIL,
whole form is a block named NIL.
make a new array for result.
M
(with-package-iterator (foo packages [:internal :external :inherited]) 8 Fu 9
d ∗ )∗ formP∗ ) >bit-eqv >
(declare decl > Fu
> >
>
>bit-and > >
>
⊲ Return values of form s. In forms, successive invocations > Fu
>bit-andc1 >
>
>
> >
>
of (foo) return: T if a symbol is returned; a symbol from >
> Fu >
>
>bit-andc2
> Fu >
>
packages; accessibility (:internal, :external, or :inherited); < =
bit-nand ^ ^
and the package the symbol belongs to. ( Fu bit-array-a bit-array-b [result-bit-array NIL ])
>bit-ior
> Fu >
>
>
> >
>
Fu
(require module [paths NIL ]) >bit-orc1
> >
>
>
> Fu >
>
>bit-orc2
var
⊲ If not in ∗modules∗, try paths to load module from. Sig- > >
>
>
> Fu
bit-xor >
>
nal error if unsuccessful. Deprecated. >
: Fu >
;
bit-nor
Fu
(provide module ) ⊲ Return result of bitwise logical operations (cf. opera-
var Fu
⊲ If not already there, add module to ∗modules∗. Depre- tions of boole, p. 4) on bit-array-a and bit-array-b. If
cated. result-bit-array is T, put result in bit-array-a; if it is NIL,
var make a new array for result.
∗modules∗ ⊲ List of names of loaded modules.
co
array-rank-limit ⊲ Upper bound of array rank; ≥ 8.
co
14.3 Symbols array-dimension-limit
⊲ Upper bound of an array dimension; ≥ 1024.
A symbol has the attributes name, home package, property list, and
optionally value (of global constant or variable name) and function co
array-total-size-limit ⊲ Upper bound of array size; ≥ 1024.
(function, macro, or special operator name).
Fu
(make-symbol name)
⊲ Make fresh, uninterned symbol name. 5.3 Vector Functions
Fu
(gensym [s G ]) Vectors can as well be manipulated by sequence functions; see sec-
⊲ Return fresh, uninterned symbol #:sn with n from tion 6.
var var
∗gensym-counter∗. Increment ∗gensym-counter∗. Fu
Fu ˆ ˜ (vector foo ∗ ) ⊲ Return fresh simple vector of foo s.
(gentemp prefix T [package ∗package∗
var ] )
Fu
⊲ Intern fresh symbol in package. Deprecated. (svref vector i) ⊲ Return element i of simple vector . setfable.
Fu
(copy-symbol symbol [props NIL ]) Fu
^)
(vector-push foo vector
⊲ Return uninterned copy of symbol . If props is T, give ⊲ Return NIL if vector ’s fill pointer equals size of vector .
copy the same value, function and property list. Otherwise replace element of vector pointed to by fill
Fu pointer with foo; then increment fill pointer.
(symbol-name symbol )
Fu
(symbol-package symbol ) Fu
Fu
(symbol-plist symbol ) ^ [num])
(vector-push-extend foo vector
Fu
(symbol-value symbol ) ⊲ Replace element of vector pointed to by fill pointer with
Fu
(symbol-function symbol ) foo, then increment fill pointer. Extend vector ’s size by
⊲ Name, package, property list, value, or function, respec- ≥ num if necessary.
tively, of symbol . setfable.
Fu
8 9 ^)
(vector-pop vector
 gF ff >
>’variable ’function >
> ⊲ Return element of vector its fillpointer points to after
< =
documentation ’compiler-macro decrementation.
( gF foo )
(setf documentation) new-doc >
>’method-combination > >
: ; Fu
(fill-pointer vector ) ⊲ Fill pointer of vector . setfable.
’structure ’type ’setf T
⊲ Get/set documentation string of foo of given type.

42 11
Common Lisp Quick Reference Common Lisp Quick Reference

6 Sequences 14 Packages and Symbols


6.1 Sequence Predicates 14.1 Predicates
 Fu ff Fu
every (symbolp foo)
( Fu test sequence + ) Fu
notevery (packagep foo) ⊲ T if foo is of indicated type.
Fu
⊲ Return NIL or T, respectively, as soon as test on any set (keywordp foo)
of corresponding elements of sequences returns NIL.
 Fu ff
some 14.2 Packages
( Fu test sequence + )
notany
⊲ Return value of test or NIL, respectively, as soon as test :bar keyword:bar ⊲ Keyword, evaluates to :bar .
on any set of corresponding elements of sequences returns
non-NIL. package:symbol ⊲ Exported symbol of package.
8˛ 9
> ˛:from-end bool > package::symbol ⊲ Possibly unexported symbol of package.
>˛˛:test functionNIL >
> >
>
> >
#’eql > 8˛ 9

> > ˛(:nicknames nick ∗ )∗
>
> ˛ :test-not function > >
> >
> ˛ >
>
>
<˛˛ >
= >
> ˛(:documentation string) >
>
Fu :start1 start-a 0 >
>˛ >
>
(mismatch sequence-a sequence-b ˛ ˛ ) >
> ˛(:intern interned-symbol ∗ ) ∗ >
>
> :start2 start-b > >
> ˛ >
>
>
> ˛ 0 >
> >˛(:use used-package )
< ∗ ∗ >
=
>
> ˛ >
> ˛
>
> ˛:end1 end-a NIL >
>
M
(defpackage foo ˛(:import-from pkg imported-symbol ) ∗ ∗
)
>˛˛:end2 end-b NIL
> >
> > ˛ >
> > > pkg shd-symbol ∗ )∗ >

:key function
; >˛˛(:shadowing-import-from
>
>
>
>
>
>
> ˛(:shadow shd-symbol ∗ )∗ >
>
⊲ Return position in sequence-a where sequence-a and >
> ˛ >
>
>
>˛(:export exported-symbol ∗ )∗ >
>
sequence-b begin to mismatch. Return NIL if they match : ˛(:size int) ;
entirely.
⊲ Create or modify package foo with interned-symbol s,
symbols from used-package s, imported-symbol s, and
shd-symbol s. Add shd-symbol s to foo’s shadowing list.
6.2 Sequence Functions ˛ ff
Fu Fu ˛:nicknames (nick ∗ ) NIL
(make-sequence sequence-type size [:initial-element foo]) (make-package foo ˛˛ ∗ )
:use (used-package )
⊲ Make sequence of sequence-type with size elements.
⊲ Create package foo.
Fu
(concatenate type sequence ∗ ) Fu
(rename-package package new-name [new-nicknames NIL ])
⊲ Return concatenated sequence of type. ⊲ Rename package. Return renamed package.
Fu
^
(merge type sequence-a ^ test [:key function NIL ])
sequence-b M
c
(in-package foo) ⊲ Make package foo current.
⊲ Return interleaved sequence of type. Merged sequence  Fu ff
will be sorted if both sequence-a and sequence-b are sorted. use-package
( Fu other-packages [package ∗package∗
var ])
˛ ff unuse-package
Fu ˛:start start 0 ⊲ Make exported symbols of other-packages available in
^ foo ˛˛
(fill sequence )
:end end NIL package, or remove them from package, respectively. Re-
⊲ Return sequence after setting elements between start and turn T.
end to foo.
Fu
Fu (package-use-list package)
Fu
(length sequence) (package-used-by-list package)
⊲ Return length of sequence (being value of fill pointer if ⊲ List of other packages used by/using package.
applicable).
8˛ 9 Fu
^
(delete-package package)
> ˛:from-end bool NIL >
>
> ˛ >
> ⊲ Delete package. Return T if successful.
>
> ˛ :test function >
#’eql >
>
< ˛ >
Fu ˛ :test-not function = var
∗package∗ common-lisp-user ⊲ The current package.
(count foo sequence ˛˛ )
>˛:start start 0
> >
>
>
> ˛ >
> Fu
>
>˛:end end NIL >
> (list-all-packages) ⊲ List of registered packages.
: ˛:key function ;
Fu
⊲ Return number of elements in sequence which match foo. (package-name package) ⊲ Name of package .
8˛ 9 Fu
(package-nicknames package) ⊲ List of nicknames of package.
˛
 Fu ff >˛:from-end bool NIL >
>
< >
=
count-if ˛:start start 0 Fu
( Fu test sequence ˛˛ ) (find-package name) ⊲ Package with name (case-sensitive).
count-if-not >
> :end end NIL >
:˛˛ >
; Fu
:key function (find-all-symbols foo)
⊲ Return number of elements in sequence which satisfy test. ⊲ List of symbols foo from all registered packages.
Fu  Fu ff
(elt sequence index ) intern
⊲ Return element of sequence pointed to by zero-indexed ( Fu foo [package ∗package∗
var ])
find-symbol
index . setfable. ⊲ Intern or find, respectively, symbol foo in package. Sec-
Fu ond return value is one of :internal, :external, or :inherited
(subseq sequence start [end NIL ]) Fu 2 2 2
⊲ Return subsequence of sequence between start and end. (or NIL if intern created a fresh symbol).
2
setfable. Fu
 Fu ff (unintern symbol [package ∗package∗
var ])
sort ⊲ Remove symbol from package, return T on success.
( Fu ^ test [:key function])
sequence
stable-sort  Fu ff
⊲ Return sequence sorted. Order of elements considered import
( Fu symbols [package ∗package∗
var ])
equal is not guaranteed/retained, respectively. shadowing-import
Fu ⊲ Make symbols internal to package. Return T. In case of
(reverse sequence) a name conflict signal correctable package-error or shadow
Fu ⊲ Return sequence in reverse order.
^
(nreverse sequence) the old symbol, respectively.

12 41
Common Lisp Quick Reference Common Lisp Quick Reference
8˛ 9 8˛ 9
<˛˛:start start 0 =˜˜ > ˛:from-end bool NIL >
>˛ >
˛:end end NIL >
> ˛ :test function #’eql >
>
) > >
:˛˛ ;  Fu ff <˛˛
> >
=
:junk-allowed bool NIL find ˛ :test-not test
( Fu foo sequence ˛ )
⊲ Return pathname converted from string, pathname, or position >
>˛ :start start 0 >
>
stream foo; and position where parsing stopped. >
> ˛ >
>
>
> :end end >
2 :˛˛ NIL >
;
:key function
Fu
(merge-pathnames
ˆ pathname ⊲ Return first element in sequence which matches foo, or
default-pathname ∗default-pathname-defaults∗
var its position relative to the begin of sequence, respectively.
˜
[default-version :newest ] ) 8 Fu 9 8˛ 9
⊲ Return pathname after filling in missing components >find-if > > ˛:from-end bool NIL >
>
< Fu >
= <˛˛
> >
=
from default-pathname . find-if-not :start start 0
( Fu test sequence ˛˛ )
>
>position-if >
> >
> :end end >
var
∗default-pathname-defaults∗ : Fu ; :˛˛ NIL >
;
position-if-not :key function
⊲ Pathname to use if one is needed and none supplied. ⊲ Return first element in sequence which satisfies test, or
Fu its position relative to the begin of sequence, respectively.
(user-homedir-pathname [host ]) ⊲ User’s home directory.
8˛ 9
˛
Fu
(enough-namestring path [root-path ∗default-pathname-defaults∗ ]) >˛:from-end
>
>  bool NIL >>
˛ :test function #’eql >
var
>
> >
>
⊲ Return minimal path string to sufficiently describe path >
>˛˛ >
>
>
> :test-not function >
>
relative to root-path. >
<˛˛ >
=
Fu :start1 start-a
(search sequence-a sequence-b ˛˛ 0 )
Fu >
> :start2 start-b 0 >
(namestring path) >˛˛
>
>
>
>
Fu
(file-namestring path) >
> ˛:end1 end-a NIL >
>
>
>˛:end2 end-b NIL >
>
Fu
(directory-namestring path) >
> ˛ >
>
:˛ ;
Fu
(host-namestring path) :key function
⊲ Return string representing full pathname; name, type, ⊲ Search sequence-b for a subsequence matching
and version; directory name; or host name, respectively, of sequence-a. Return position in sequence-b, or NIL.
path. 8˛ 9
> ˛:from-end bool NIL >
Fu >
> ˛ >
>
> ˛ >
(translate-pathname path wildcard-path-a wildcard-path-b ) >
>
> ˛ :test function #’eql >
>
⊲ Translate path from wildcard-path-a into wildcard-path-b.  Fu ff<>˛ :test-not function > >
=
remove foo sequence ˛
Return new path. ( Fu ˛:start start )
^
delete foo sequence >˛˛ 0
>
>
> >
>
Fu >
> ˛:end end NIL >
>
(pathname path) ⊲ Pathname of path. >˛:key function
> >
>
>
:˛˛ >
;
Fu :count count NIL
(logical-pathname logical-path ) ⊲ Make copy of sequence without elements matching foo.
⊲ Logical pathname of logical-path . Logical pathnames
 ffare
{dir *}+ 8 Fu ff 98˛ 9
represented as all-uppercase #P"[host :][:]{ ;}∗ > ˛:from-end bool NIL >
** >remove-if
>
< Fu
>
test sequence>
=
>
> ˛
<˛:start start 0
>
>
=
 ff remove-if-not ˛
ˆ {type *}+ ˜ ( Fu ff ˛:end end NIL )
{name *}∗ . [.{version * newest NEWEST}] ". >
>delete-if >>˛ >
LISP : Fu ^ >
test sequence ;>
:˛˛:key function
> >
>
;
delete-if-not
Fu
:count count NIL
(logical-pathname-translations logical-host ) ⊲ Make copy of sequence with all (or count ) elements sat-
⊲ List of (from-wildcard to-wildcard ) translations for isfying test removed.
logical-host . setfable.
8˛ 9
Fu > ˛:from-end bool NIL >
>
> ˛ >
(load-logical-pathname-translations logical-host ) >˛ :test function #’eql >>
⊲ Load logical-host ’s translations. Return NIL if already  Fu ff>
<˛˛
> >
>
=
remove-duplicates sequence ˛ :test-not function
loaded; return T if successful. ( Fu ˛ )
^
delete-duplicates sequence >
> ˛:start start 0 >
>
>
>˛:end end NIL >
>
Fu >
> >
(translate-logical-pathname pathname ) :˛˛ >
;
⊲ Physical pathname corresponding to (possibly logical) :key function
pathname . ⊲ Make copy of sequence without duplicates.
8˛ 9
Fu ˛
(probe-file file) >˛:from-end
>
>  bool NIL >>
Fu
(truename file) >
> ˛ :test function #’eql >
>
>
>
>˛˛ >
>
⊲ Canonical name of file. If file does not exist, return  Fu ff><˛ :test-not function > =
substitute new old sequence ˛:start start
NIL/signal file-error, respectively. ( Fu ˛ )
^
nsubstitute new old sequence >
> ˛:end end NIL
0
>
>
>
> ˛ >
>
Fu
(file-write-date file) ⊲ Time at which file was last written. >˛
> >
>
>
> :key function >
:˛˛ >
;
Fu :count count NIL
(file-author file) ⊲ Return name of file owner. ⊲ Make copy of sequence with all (or count ) olds replaced
Fu by new .
(file-length stream) ⊲ Return length of stream .
8 Fu ff 9 8˛ 9
Fu
(rename-file foo bar ) > ˛:from-end bool NIL >
>substitute-if
>
< Fu new test sequence >
>
=
>
> ˛
<˛:start start 0
>
>
=
⊲ Rename file foo to bar . Unspecified components of path substitute-if-not ff ˛
bar default to those of foo. Return new pathname, old ( Fu ˛:end end NIL )
>
>nsubstitute-if > > ˛ >
2 : Fu ^ >
new test sequence ; >
>
:˛˛:key function >
>
;
physical file name, and new physical file name. nsubstitute-if-not
3 :count count NIL
Fu ⊲ Make copy of sequence with all (or count ) elements sat-
(delete-file file) ⊲ Delete file. Return T. isfying test replaced by new .
Fu
(directory path) ⊲ List of pathnames matching path. 8˛ 9
> ˛:start1 start-a 0 >
<˛˛
> >
=
Fu Fu :start2 start-b 0
(ensure-directories-exist path [:verbose bool ]) ^
(replace sequence-a sequence-b ˛˛ )
>
> :end1 end-a NIL >
⊲ Create parts of path if necessary. Second return value is :˛˛ >
;
T if something has been created. :end2 end-b NIL
2 ⊲ Replace elements of sequence-a with elements of
sequence-b.

40 13
Common Lisp Quick Reference Common Lisp Quick Reference

Fu Fu
(map type function sequence + ) ^ [:abort bool NIL ])
(close stream
⊲ Apply function successively to corresponding elements of ⊲ Close stream. Return T if stream had been open. If :abort
the sequences. Return values as a sequence of type. If type is T, delete associated file.
is NIL, return NIL.
M
d ∗ )∗ formP∗ )
(with-open-file (stream path open-arg ∗ ) (declare decl
Fu
Fu
^ ⊲ Use open with open-arg s to temporarily create stream to
(map-into result-sequence function sequence ∗ )
path; return values of form s.
⊲ Store into result-sequence successively values of function
applied to corresponding elements of the sequences. M
^ (declare decl
(with-open-stream (foo stream) d ∗ )∗ formP∗ )
8˛ 9 ⊲ Evaluate forms with foo locally bound to stream. Return
> ˛:initial-value foo NIL > values of form s.

> >
<˛:from-end bool NIL > =
Fu ˛ 8˛ 9
(reduce function sequence ˛:start start 0 )
>
> ˛ >
> <˛˛:index index
]=
>˛:end end NIL
: >
; M
˛
(with-input-from-string (foo string ˛:start start 0 ) (declare
˛ :˛ ;
:key function
:end end NIL
⊲ Starting with the first two elements of sequence, apply P
function successively to its last return value together with d ∗ )∗ form ∗ )
decl
the next element of sequence. Return last value of function. ⊲ Evaluate forms with foo locally bound to input
string-stream from string. Return values of form s; store
Fu next reading position into index .
(copy-seq sequence)
⊲ Copy of sequence with shared elements. M
(with-output-to-string (foo [s^ tring NIL ] [:element-type type character ])
d ∗ )∗ formP∗ )
(declare decl
⊲ Evaluate forms with foo locally bound to an output
string-stream. Append output to string and return values
7 Hash Tables of form s if string is given. Return string containing output
otherwise.
Key-value storage similar to hash tables can as well be achieved us- Fu
(stream-external-format stream)
ing association lists and property lists; see pages 9 and 16.
⊲ External file format designator.
Fu var
(hash-table-p foo) ⊲ Return T if foo is of type hash-table. ∗terminal-io∗ ⊲ Bidirectional stream to user terminal.
var
8˛ 9 ∗standard-input∗
> ˛:test {Fu Fu Fu Fu
eq eql equal equalp} #’eql > var
<˛˛
> >
= ∗standard-output∗
var
(make-hash-table ˛˛:size int
Fu
) ∗error-output∗
>
>˛ :rehash-size num >
> ⊲ Standard input stream, standard output stream, or stan-
: ˛:rehash-threshold num ;
dard error output stream, respectively.
⊲ Make a hash table.
var
∗debug-io∗
Fu var
(gethash key hash-table [default NIL ]) ∗query-io∗
⊲ Return object with key if any or default otherwise; and ⊲ Bidirectional streams for debugging and user interaction.
T if found, NIL otherwise. setfable.
2 2

Fu
(hash-table-count hash-table) 13.7 Pathnames and Files
⊲ Number of entries in hash-table. Fu
(make-pathname
8˛ 9
˛
>˛:host {host NIL :unspecific}
>
>
>
>
>
Fu
^
(remhash key hash-table) >
> ˛:device {device NIL :unspecific} >
>
>
> ˛ 8 >
>
⊲ Remove from hash-table entry with key and return T if it >
>˛˛ > {directory :wild NIL :unspecific} >
>
>
> >
> 8 9 >
>
existed. Return NIL otherwise. >
> ˛ >
> directory
∗ >
>

> >
< >
> >
> >
>
>
> ˛  ff >
< :wild >
= >
>
> ˛
>˛:directory :absolute >
>
>
> > ( :wild-inferiors ) >
>
Fu
^
(clrhash hash-table) ⊲ Empty hash-table. <˛ >
> :relative > > =
˛ >
> >
> :up >
>
˛ >
: : ; )
>
> ˛ :back >
>
Fu >
> ˛ >
>
(maphash function hash-table) >˛:name {file-name :wild NIL :unspecific}
> >
>
>
> ˛ >
>
⊲ Iterate over hash-table calling function on key and value. >
> ˛ >
>
>
> ˛:type {file-type :wild NIL :unspecific} >
>
Return NIL. >
> ˛ >
>
> ˛:version {:newest version :wild NIL :unspecific}> >
>

> >
>
>
> ˛:defaults path host from ∗default-pathname-defaults∗
var >
>
M
d ∗ )∗ formP∗ ) >
:˛˛ >
;
(with-hash-table-iterator (foo hash-table) (declare decl :case {:local :common} :local
⊲ Return values of form s. In forms, invocations of (foo) ⊲ Construct pathname. For :case :local, leave case of com-
return: T if an entry is returned; its key; its value. ponents unchanged. For :case :common, leave mixed-case
components unchanged; convert all-uppercase components
Fu
(hash-table-test hash-table) into local customary case; do the opposite with all-lowercase
⊲ Test function used in hash-table. components.
8 Fu 9
Fu
(hash-table-size hash-table) > pathname-host >
> Fu
> >
>  ff
Fu
(hash-table-rehash-size hash-table) <pathname-device =
Fu :local
Fu ( pathname-directory path [:case ])
(hash-table-rehash-threshold hash-table) >
> Fu >
> :common :local
⊲ Current size, rehash-size, or rehash-threshold, respec- >pathname-name
: Fu
>
;
Fu
tively, as used in make-hash-table. pathname-type
Fu
(pathname-version path)
Fu ⊲ Return pathname component.
(sxhash foo)
Fu
⊲ Hash code unique for any argument equal foo. Fu ˆ
(parse-namestring foo host
ˆ
default-pathname ∗default-pathname-defaults∗
var

14 39
Common Lisp Quick Reference Common Lisp Quick Reference

13.6 Streams 8 Structures


8˛ 8 9 9
>˛ >
> :input >> > M

> < = >
> (defstruct
>
>˛ :output >
> 8 9
>
>˛ :direction :input >
> foo
>
>˛ >
> :io >
> >
> >
> 8˛( 9> >
>
>˛ : ; >
> >
> ˛ :conc-name >
>
>˛ :probe > > >
> >
> >
>
>
>˛  ff >
>
>
>
>
> >˛˛
> \ foo- ]) >
>
>
>
>
>
>˛ type >
> >
> >
> ˛ (:conc-name [slot-prefix >
> >
>

>˛ :element-type character >
> >
> >
> ˛ ( ) >
> >
>
>
> :default >
> >
> >
> ˛ :constructor ∗ >
> >
>

> 8 9 >
> >
> >
> ˛ ˆ ˜ >
> >
>
>
>˛ > :new-version > >
> >
> >
> ˛ \ MAKE-foo [(ord-λ [ )] )
∗ >
> >
>
>
>˛ >
>:error >
> >
> >
> >
> ˛ (:constructor maker >
> >
>
>
>˛ >
> >
> >
> >
> >
>˛ ( >
> >
>
<˛ >
> >
> = >
> >
> ˛ :copier >
> >
>
Fu ˛ >
> :rename >
> >
> >
> ˛ >
> >
>
(open path ˛ < = ) >
> >
> ˛ \ COPY-foo ]) >
> >
>
>
>˛ :rename-and-delete >
> >
> >˛ (:copier [copier
> >
> >
>
>
>˛:if-exists :new-version if path >> >
> >
> ˛ 8 9 >
∗ >
>
>
>
>˛ >
> :overwrite >
> specifies :newest; >
> >
< >
>˛ d >
> >
=
>
>˛ >
> >
> >
> >
<˛ >
< slot (˛ >
) = = >

> >:append
> > NIL otherwise
> >
> ˛(:include s\ ˛
>
>˛ >
> :supersede >
> >
> > (foo ˛ truct ˛:type \
sl-type ) )>
>˛ > > > >
> > ˛ > d ])> >

>
>
: ; >
>
> >
> >
>˛ :(slot [init ˛˛ b ; >>
>>
>
>
>
>˛ NIL 8 9 >
> >
> >
> ˛ :read-only b >
> >
>
>˛ > > > 8 8 9 > >
>
>˛ <:error = >
> >
> >
> ˛ > < list = ˛ >
> >
>
> > >
> >
> ˛ > ˛:named >
> >
>
>
>
˛
˛ :if-does-not-exist :create >
> >
> >˛>
>
>
(:type vector ) ˛ >>
> >
>
>˛ NIL for :direction :probe; >
> > > ˛<> ˛(:initial-offset n > >
> : ; > >
> >
> : ; b ) > >
>

: NIL {:create :error} otherwise >
>
; >
> >˛˛ (
> d
(vector type) >
>>
> >
>
˛ >
> >
> ˛ > >
> >
>
:external-format format :default >
> >
>˛> \ ])
> (:print-object [o-printer >
>> >
>
> >
> ˛>> >
> >
>
⊲ Open file-stream to path . >
> >
> : \
˛ (:print-function [f-printer]) >
> >
>
>
> >
> ˛ >
> >
>
> >˛
> >>
> >
>
Fu >
> >
> :predicate > >
(make-concatenated-stream input-stream ∗ ) : :˛˛ >
;> ;
Fu \ foo-P ])
(:predicate [p-name
(make-broadcast-stream output-stream ∗ ) 8 9∗
Fu
(make-two-way-stream input-stream-part output-stream-part ) >
<slot (˛ ) > =
Fu
(make-echo-stream from-input-stream to-output-stream) d ˛ \
[doc] ˛:type slot-type )
:(slot [init ˛˛:read-only bool
> ])>
Fu
(make-synonym-stream variable-bound-to-stream) d ;
⊲ Return stream of indicated type. ⊲ Define structure foo together with functions MAKE-foo,
Fu ˆ ˜ COPY-foo and foo-P; and setfable accessors foo-slot . In-
(make-string-input-stream string start 0 [end NIL ] ) stances are of class foo or, if defstruct option :type is given,
⊲ Return a string-stream supplying the characters from of the specified type. They can be created by (MAKE-foo
string. {:slot value}∗ ) or, if ord-λ (see p. 16) is given, by (maker
Fu arg ∗ {:key value}∗ ). In the latter case, arg s and :keys
(make-string-output-stream [:element-type type character ])
correspond to the positional and keyword parameters de-
⊲ Return a string-stream accepting characters (available via
Fu fined in ord-λ whose var s in turn correspond to slot s.
get-output-stream-string). gF
:print-object/:print-function generate a print-object method
Fu for an instance bar of foo calling (o-printer bar stream)
(concatenated-stream-streams concatenated-stream )
Fu or (f-printer bar stream print-level), respectively. If :type
(broadcast-stream-streams broadcast-stream )
without :named is given, no foo-P is created.
⊲ Return list of streams concatenated-stream still has to
read from/broadcast-stream is broadcasting to. Fu
(copy-structure structure)
Fu ⊲ Return copy of structure with shared slot values.
(two-way-stream-input-stream two-way-stream)
Fu
(two-way-stream-output-stream two-way-stream)
Fu
(echo-stream-input-stream echo-stream)
Fu
(echo-stream-output-stream echo-stream)
⊲ Return source stream or sink stream of two-way-stream/
9 Control Structure
echo-stream, respectively.
9.1 Predicates
Fu
(synonym-stream-symbol synonym-stream) Fu
(eq foo bar ) ⊲ T if foo and bar are identical.
⊲ Return symbol of synonym-stream.
Fu
Fu
(eql foo bar )
^
(get-output-stream-string string-stream) ⊲ T if foo and bar are identical, or the same character, or
⊲ Clear and return as a string characters on string-stream. numbers of the same type and value.
8 9 Fu
<:start = (equal foo bar )
Fu Fu
(file-position stream [ :end ]) ⊲ T if foo and bar are eql, or are equivalent pathnames,
: ; Fu
or are conses with equal cars and cdrs, or are strings or
position Fu
⊲ Return position within stream, or set it to position and bit-vectors with eql elements below their fill pointers.
return T on success. Fu
(equalp foo bar )
Fu
(file-string-length stream foo) ⊲ T if foo and bar are identical; or are the same character
⊲ Length foo would have in stream. ignoring case; or are numbers of the same value ignoring
type; or are equivalent pathnames; or are conses or arrays
Fu
Fu of the same shape with equalp elements; or are structures
(listen [stream ∗standard-input∗
var ]) Fu
⊲ T if there is a character in input stream. of the same type with equalp elements; or are hash-tables of
the same size with the same :test function, the same keys
Fu
Fu in terms of :test function, and equalp elements.
^ ∗standard-input∗
(clear-input [stream var ])
Fu
⊲ Clear input from stream, return NIL. (not foo) ⊲ T if foo is NIL; NIL otherwise.
8 Fu 9 Fu
<clear-output = (boundp symbol ) ⊲ T if symbol is a special variable.
Fu
^ ∗standard-output∗
( force-output [stream var ]) Fu
: Fu ; (constantp foo [environment NIL ])
finish-output
⊲ End output to stream and return NIL immediately, after ⊲ T if foo is a constant form.
initiating flushing of buffers, or after flushing of buffers, Fu
respectively. (functionp foo) ⊲ T if foo is of type function.

38 15
Common Lisp Quick Reference Common Lisp Quick Reference
 ff ˘ ¯ ˆ
Fu foo
(fboundp ) ⊲ T if foo is a global function or macro. ˜ [:] [@] < ˜[prefix "" ˜;] [per-line-prefix ˜@;] body ˜;
(setf foo) suffix "" ˜: [@] >
⊲ Logical Block. Act like pprint-logical-block using body
Fu
as format control string on the elements of the list ar-
9.2 Variables gument or, with @, on the remaining arguments, which
M ff are extracted by pprint-pop. With :, prefix and suffix
defconstant c form [doc])
d default to ( and ). When closed by ˜:@>, spaces in
( M foo
defparameter body are replaced with conditional newlines.
⊲ Assign value of form to global constant/dynamic variable
foo.
{˜ [n 0 ] i ˜ [n 0 ] :i}
M ˆ ˜ ⊲ Indent. Set indentation to n relative to leftmost/to
c form [doc]
(defvar foo d )
current position.
⊲ Unless bound already, assign value of form to dynamic
variable foo.
M ff ˜ [c 1 ] [,i 1 ] [:] [@] T
setf ⊲ Tabulate. Move cursor forward to column number
( M {place form}∗ ) c+ki, k ≥ 0 being as small as possible. With :, calculate
psetf
⊲ Set places to primary values of forms. Return values of column numbers relative to the immediately enclosing
last form /NIL; work sequentially/in parallel, respectively. section. With @, move to column number c0 + c + ki
where c0 is the current position.
 sO ff
setq
( M {symbol form}∗ )
psetq
{˜ [m 1 ] ∗ ˜ [m 1 ] :∗ ˜ [n 0 ] @∗}
⊲ Set symbol s to primary values of forms. Return value of
⊲ Go-To. Jump m arguments forward, or backward, or
last form /NIL; work sequentially/in parallel, respectively.
to argument n.
Fu
^ foo)
(set symbol
⊲ Set symbol ’s value cell to foo. Deprecated. ˜ [limit] [:] [@] { text ˜}
⊲ Iteration. Use text repeatedly, up to limit, as control
M
(multiple-value-setq vars form) string for the elements of the list argument or (with @)
⊲ Set elements of vars to the values of form. Return form ’s for the remaining arguments. With : or :@, list elements
primary value. or remaining arguments should be lists of which a new
one is used at each iteration step.
M
] + foo)
(shiftf place ˆ ˆ ˜˜
⊲ Store value of foo in rightmost place shifting values of ˜ x ,y [,z ] ˆ
places left, returning first place . ⊲ Escape Upward. Leave immediately ˜< ˜>,
Fu
˜< ˜:>, ˜{ ˜}, ˜?, or the entire format operation.
M
] ∗)
(rotatef place With one to three prefixes, act only if x = 0, x = y, or
⊲ Rotate values of places left, old first becoming new last x ≤ y ≤ z, respectively.
place’s value. Return NIL.

Fu
f ˜ [i] [:] [@] [ [{text ˜;} text] [˜:; default ] ˜]
(makunbound foo) ⊲ Delete special variable foo if any. ⊲ Conditional Expression. Use the zero-indexed argu-
Fu
Fu ˆ ˜ menth (or ith if given) text as a format control sub-
(get symbol keyˆ default NIL˜ ) clause. With :, use the first text if the argument value
Fu
(getf place key default NIL ) is NIL, or the second text if it is T. With @, do nothing
⊲ First entry key from property list stored in symbol /in for an argument value of NIL. Use the only text and
place, respectively, or default if there is no key. setfable. leave the argument to be read again if it is T.
Fu
(get-properties property-list keys)
⊲ Return key and value of first entry from property-list ˜ [@] ?
2 ⊲ Recursive Processing. Process two arguments as con-
matching a key from keys, and tail of property-list start- trol string and argument list. With @, take one ar-
3
ing with that key. Return NIL, NIL, and NIL if there was no gument as control string and use then the rest of the
2 3
matching key in property-list . original arguments.
Fu
^ key)
(remprop symbol ˆ ∗
˜
M
] key) ˜ prefix {,prefix } [:] [@] /function/
(remf place ⊲ Call Function. Call function with the arguments
⊲ Remove first entry key from property list stored in stream, format-argument, colon-p, at-sign-p and
symbol /in place, respectively. Return T if key was there, prefix es for printing format-argument.
or NIL otherwise.

˜ [:] [@] W
⊲ Write. Print argument of any type obeying every
9.3 Functions printer control variable. With :, pretty-print. With
@, print without limits on length or depth.
Below, ordinary lambda
 list (ord-λ∗ ) has the ff form
ˆ ∗˜
∗ var ˆ ˜
(var &optional [&rest var ]
(var init NIL [supplied-p] ) {V #}
8 9∗
ˆ <var
 ff = ⊲ In place of the comma-separated prefix parameters:
&key var ˆ ˜ use next argument or number of remaining unprocessed
:( init NIL [supplied-p] );
arguments, respectively.
(:key var )
 ff∗
˜ˆ var ˜
[&allow-other-keys] &aux ).
(var [init NIL ])

supplied-p is T if there is a corresponding argument. init forms can


refer to any init and supplied-p to their left.

16 37
Common Lisp Quick Reference Common Lisp Quick Reference

ˆ ˆ ˆ ˜˜˜ 8  9
<M foo (ord-λ∗ ) =
˜ [min-col 0 ] ,[col-inc 1 ] ,[min-pad 0 ] ,pad-char ’ defun ∗ d ∗ )∗ [doc]
d
( (setf foo) (new-value ord-λ ) (declare decl
[:] [@] {A S} :M ∗ ;
lambda (ord-λ )
⊲ Aesthetic/Standard. Print argument of any type for P
consumption by humans/by the reader, respectively. form ∗ )
With :, print NIL as () rather than nil; with @, add ⊲ Define a function named foo or (setf foo), or an anony-
pad-char s on the left rather than on the right. mous function, respectively, which applies forms to ord-λs.
M sO
ˆ ˆ ˆ For defun, forms are enclosed in an implicit block named
˜ [radix
ˆ 10 ] ,[width] ,[pad-char ’ ] ,[comma-char ’, ]
˜˜˜˜ foo.
,comma-interval 3 [:] [@] R
sO ff  ff
⊲ Radix. (With one or more prefix arguments.) flet foo (ord-λ∗ ) \ ∗ )∗
Print argument as number; with :, group digits ( sO (( ∗ (declare local-decl
labels (setf foo) (new-value ord-λ )
comma-interval each; with @, always prepend a sign. d local-form ∗ )∗ ) (declare decl
[doc]
P d ∗ )∗ form ∗ )
P

{˜R ˜:R ˜@R ˜@:R} ⊲ Evaluate forms with locally defined functions foo. Glob-
⊲ Roman. Take argument as number and print it as ally defined functions of the same name are shadowed. Each
sO
English cardinal number, as English ordinal number, as foo is also the name of an implicit block around its corre-
∗ sO
Roman numeral, or as old Roman numeral, respectively. sponding local-form . Only for labels, functions foo are
ˆ ˆ
[width] ,[pad-char ’ ] ,[comma-char ’, ] visible inside local-forms . Return values of form s.
˜ ˆ ˜˜˜
,comma-interval 3 [:] [@] {D B O X}  ff
⊲ Decimal/Binary/Octal/Hexadecimal. Print integer
sO foo
(function M ∗ )
argument as number. With :, group digits (lambda form )
comma-interval each; with @, always prepend a sign. ⊲ Return lexically innermost function named foo or a lexi-
M
ˆ ˆ ˆ cal closure of the lambda expression.
[width]
˜ ˆ ,[dec-digits] ,[shift 0 ] ,[overflow-char ]
˜˜˜˜  ff
,pad-char ’ [@] F Fu function
⊲ Fixed-Format Floating-Point. With @, always pre- (apply arg ∗ args)
(setf function)
pend a sign. ⊲ Values of function called with args and the list elements
ˆ ˆ ˆ Fu Fu Fu
˜ [width]
ˆ
,[int-digits] ,[exp-digits] ,[scale-factor 1 ]
ˆ ˆ ˜˜˜˜˜˜
of args. setfable if function is one of aref, bit, and sbit.
,[overflow-char ] ,[pad-char ’ ] ,exp-char Fu
[@] {E G} (funcall function arg∗ ) ⊲ Values of function called with arg s.
⊲ Exponential/General Floating-Point. Print argument sO
as floating-point number with int-digits before decimal (multiple-value-call function form ∗ )
point and exp-digits in the signed exponent. With ˜G, ⊲ Call function with all the values of each form as its ar-
choose either ˜E or ˜F. With @, always prepend a sign. guments. Return values returned by function .
ˆ ˆ ˆ ˜˜˜ Fu
˜ [dec-digits 2 ] ,[int-digits 1 ] ,[width 0 ] ,pad-char ’ [:] (values-list list) ⊲ Return elements of list .
[@] $
⊲ Monetary Floating-Point. Print argument as fixed- Fu
(values foo ∗ )
format floating-point number. With :, put sign before ⊲ Return as multiple values the primary values of the foos.
any padding; with @, always prepend a sign. setfable.
{˜C ˜:C ˜@C ˜@:C} Fu
⊲ Character. Print, spell out, print in #\ syntax, or (multiple-value-list form) ⊲ List of the values of form .
tell how to type, respectively, argument as (possibly M
non-printing) character. (nth-value n form )
⊲ Zero-indexed nth return value of form.
{˜( text ˜) ˜:( text ˜) ˜@( text ˜) ˜:@( text ˜)}
⊲ Case-Conversion. Convert text to lowercase, convert Fu
(complement function)
first letter of each word to uppercase, capitalize first
⊲ Return new function with same arguments and same side
word and convert the rest to lowercase, or convert to
effects as function, but with complementary truth value.
uppercase, respectively.
Fu
{˜P ˜:P ˜@P ˜:@P} (constantly foo)
⊲ Plural. If argument eql 1 print nothing, otherwise ⊲ Function of any number of arguments returning foo.
print s; do the same for the previous argument; if ar-
Fu
gument eql 1 print y, otherwise print ies; do the same (identity foo) ⊲ Return foo.
for the previous argument, respectively.
Fu
˜ [n 1 ] % ⊲ Newline. Print n newlines. (function-lambda-expression function)
⊲ If available, return lambda expression of function, NIL if
˜ [n 1 ] & 2
⊲ Fresh-Line. Print n − 1 newlines if output stream is function was defined in an environment without bindings,
at the beginning of a line, or n newlines otherwise. and name of function.
3
{˜ ˜: ˜@ ˜:@ }  ff
⊲ Conditional Newline. Print a newline like Fu foo
(fdefinition )
pprint-newline with argument :linear, :fill, :miser, (setf foo)
or :mandatory, respectively. ⊲ Definition of global function foo. setfable.
{˜:←֓ ˜@←֓ ˜←֓} Fu
⊲ Ignored Newline. Ignore newline, or whitespace fol- (fmakunbound foo)
lowing newline, or both, respectively. ⊲ Remove global function or macro definition foo.

˜ [n 1 ] | ⊲ Page. Print n page separators. co


call-arguments-limit
co
˜ [n 1 ] ˜ ⊲ Tilde. Print n tildes. lambda-parameters-limit
ˆ ˆ ˆ ˜˜˜
⊲ Upper bound of the number of function arguments or
˜ [min-col 0 ] ˆ,[col-inc 1 ] ,[min-pad 0 ] ,pad-char
˜ ’
[:] [@] < nl-text ˜[spare 0 [,width]]:; {text ˜;}∗ text lambda list parameters, respectively; ≥ 50.
˜> co
multiple-values-limit
⊲ Justification. Justify text produced by texts in a field
⊲ Upper bound of the number of values a multiple value
of at least min-col columns. With :, right justify; with
can have; ≥ 20.
@, left justify. If this would leave less than spare char-
acters on the current line, output nl-text first.

36 17
Common Lisp Quick Reference Common Lisp Quick Reference
8 9
9.4 Macros >
>:linear >
>
< =ˆ ˜
Fu :fill ^ ∗standard-output∗
Below, macro lambda ∗ ) has the form of either (pprint-newline stream var )
 list (macro-λ ff∗ >:miser
>
:
>
>
;
var :mandatory
([&whole var ] [E ] [E ]
(macro-λ∗ ) ⊲ Print a conditional newline if stream is a pretty printing
8 9∗
<var ff = stream. Return NIL.
[&optional var ˆ ˜ ] [E ]
:( init [supplied-p] ); var Fu
(macro-λ∗ ) NIL ∗print-array∗ ⊲ If T, print arrays readably.
 ff ff
&rest rest-var var
[ ] [E ] ∗print-base∗ 10 ⊲ Radix for printing rationals, from 2 to 36.
&body (macro-λ∗ )
8 9∗
>var
>
< 8 9 >
>
=
var
∗print-case∗ :upcase
ˆ <var  =ˆ
&key ff ˜ [E ] ⊲ Print symbol names all uppercase (:upcase), all lowercase
>(:(:key var
>
: );
init NIL [supplied-p] )> >
; (:downcase), capitalized (:capitalize).
(macro-λ∗ )
 ff∗
˜ var var
∗print-circle∗ NIL
[&allow-other-keys] [&aux ] [E ])
(var [init NIL ]) ⊲ If T, avoid indefinite recursion while printing circular
or  ff∗
var structure.
([&whole var ] [E ] ∗ [E ] [&optional var
(macro-λ ) ∗print-escape∗ T
8 9∗
< var ff = ⊲ If NIL, do not print escape characters and package pre-
var ˆ ˜ ] [E ] . rest-var ). fixes.
:( ∗ init NIL [supplied-p] );
(macro-λ ) var
∗print-gensym∗ T
One toplevel [E ] may be replaced by &environment var . supplied-p ⊲ If T, print #: before uninterned symbols.
is T if there is a corresponding argument. init forms can refer to
var
any init and supplied-p to their left. ∗print-length∗ NIL
M ff ff var
∗print-level∗ NIL
defmacro foo var
( Fu (macro-λ∗ ) (declare ∗print-lines∗ NIL
define-compiler-macro (setf foo)
d ∗ )∗ [doc] P
d form ∗ ) ⊲ If integer, restrict printing of objects to that number of
decl elements per level/to that depth/to that number of lines.
⊲ Define macro foo which on evaluation as (foo tree) applies
var
expanded form s to arguments from tree, which corresponds ∗print-miser-width∗
to tree-shaped macro-λs. forms are enclosed in an implicit ⊲ If integer and greater than the width available for print-
sO
block named foo. ing a substructure, switch to the more compact miser style.
M
(define-symbol-macro foo form) var
∗print-pretty∗ ⊲ If T, print pretty.
⊲ Define symbol macro foo which on evaluation evaluates
expanded form. var
∗print-radix∗ NIL ⊲ If T, print rationals with a radix indicator.
sO
\ ∗ )∗ [doc]
(macrolet ((foo (macro-λ∗ ) (declare local-decl d var
P∗ ∗ d ∗ ∗ P∗ ∗print-readably∗ NIL
macro-form ) ) (declare decl ) form ) Fu
⊲ If T, print readably or signal error print-not-readable.
⊲ Evaluate forms with locally defined mutually invisible
sO
macros foo which are enclosed in implicit blocks of the same var
∗print-right-margin∗ NIL
name. ⊲ Right margin width in ems while pretty-printing.
sO
d ∗ )∗ formP∗ )
(symbol-macrolet ((foo expansion-form)∗ ) (declare decl Fu ˆ
⊲ Evaluate forms with locally defined symbol macros foo. (set-pprint-dispatch type function priority 0
˜
[table ∗print-pprint-dispatch∗ ] )
var
M
(defsetf ( \
function ⊲ Install entry comprising function of arguments stream
)
\ [doc]
updater d and object to print; and priority as type into table. If
) function is NIL, remove type from table. Return NIL.
d ∗ )∗ [doc]
(setf-λ∗ ) (s-var ∗ ) (declare decl d formP∗
where defsetf ∗ the form (var ∗
 lambda list (setf-λ ) has ff
Fu
∗˜ (pprint-dispatch foo [table ∗print-pprint-dispatch∗
var ])
ˆ var ˆ
&optional ˜ [&rest var ] ⊲ Return highest priority function associated with type of
(var init NIL [supplied-p] )
8 9∗ foo and T if there was a matching type specifier in table.
ˆ <var
 ff = 2

&key var ˆ ˜ Fu
:( init NIL [supplied-p] ); (copy-pprint-dispatch [table ∗print-pprint-dispatch∗
var ])
(:key var )
˜ˆ ˜ ⊲ Return copy of table or, if table is NIL, initial value of
[&allow-other-keys] &environment var ) var
∗print-pprint-dispatch∗.
⊲ Specify how to setf a place accessed by function.
Short form: (setf (function arg ∗ ) value-form) is replaced var
∗print-pprint-dispatch∗ ⊲ Current pretty print dispatch table.
by (updater arg ∗ value-form); the latter must return
value-form. Long form: on invocation of (setf (function
arg ∗ ) value-form), forms must expand into code that sets
the place accessed where setf-λ and s-var ∗ describe the ar- 13.5 Format
guments of function and the value(s) to be stored, respec- M
\)
(formatter control
tively; and that returns the value(s) of s-var ∗ . forms are
sO ⊲ Return function of stream and a &rest argument applying
enclosed in an implicit block named function. Fu
format to stream, control , and the &rest argument return-
M
d ∗ )∗ [doc]
(define-setf-expander function (macro-λ∗ ) (declare decl d ing NIL or any excess arguments.
P
form ∗ ) Fu
⊲ Specify how to setf a place accessed by function. On in- (format {T NIL out-string out-stream} control arg ∗ )
vocation of (setf (function arg ∗ ) value-form), form ∗ must ⊲ Output string control which may contain ˜ directives
expand into code returning arg-vars, args, newval-vars, possibly taking some args. Alternatively, control can be
Fu M
set-form, and get-form as described with get-setf-expansion a function returned by formatter which is then applied to

where the elements of macro lambda list macro-λ∗ are out-stream and arg . Output to out-string, out-stream or,
var
bound to corresponding args. form s are enclosed in an im- if first argument is T, to ∗standard-output∗. Return NIL. If
sO
plicit block named function. first argument is NIL, return formatted output.

18 35
Common Lisp Quick Reference Common Lisp Quick Reference

Fu Fu
^ ∗standard-output∗
(write-char char [stream var ]) (get-setf-expansion place [environment NIL ])
⊲ Output char to stream. ⊲ Return lists of temporary variables arg-vars and of cor-
responding args as given with place, list newval-vars with
 Fu ff ˛ ff 2 3
write-string ˆ ˆ ˛:start start 0 ˜˜ temporary variables corresponding to the new values, and
( Fu ^ ∗standard-output∗
string stream var ˛ )
write-line ˛:end end NIL set-form and get-form specifying in terms of arg-vars and
4 5
⊲ Write string to stream without/with a trailing newline. newval-vars how to setf and how to read place.
Fu M ˆ
^
(write-byte byte stream) ⊲ Write byte to binary stream. (define-modify-macro foo ( &optional
 ff∗
var ˆ ˜
˛ ff ˜ d
[&rest var ]) function [doc])
Fu ˛:start start 0 (var init NIL [supplied-p] )
^
(write-sequence sequence stream ˛
˛:end end NIL ) ⊲ Define macro foo able to modify a place. On invocation
⊲ Write elements of sequence to binary or character stream. of (foo place arg ∗ ), the value of function applied to place
8˛ 9 and args will be stored into place and returned.
˛
>˛:array bool
>
>
>
>
>
co
lambda-list-keywords
>
> ˛:base radix >
>
>
>˛˛ 8 >
> ⊲ List of macro lambda list keywords. These are at least:
>
> <:upcase >
>
>
> ˛ >
>
>˛:case :downcase
> >
>
>
> ˛ : >
> &whole var
>
> ˛ :capitalize >
>
>
> ˛ >
> ⊲ Bind var to the entire macro call form.
>
> ˛ :circle bool >
>
>
> ˛ >
> &optional var ∗
>
> ˛:escape bool >
>
>
> ˛ >
> ⊲ Bind var s to corresponding arguments if any.
>
> ˛ :gensym bool >
>
 Fu ff >
> ˛ >
> {&rest &body} var
<˛:length {int NIL} =
write ˛ ⊲ Bind var to a list of remaining arguments.
( Fu foo ˛:level {int NIL} )
write-to-string >
> ˛ >
>
>
> ˛:lines {int NIL} >
> &key var ∗

> >
>
>
> ˛:miser-width {int NIL} >
> ⊲ Bind var s to corresponding keyword arguments.
>
> ˛ >
>
>
> ˛ :pprint-dispatch dispatch-table >
> &allow-other-keys
>
> ˛ >
>
>
> ˛:pretty bool >
> ⊲ Suppress keyword argument checking. Callers can do

> >
>
>
> ˛ :radix bool >
> so using :allow-other-keys T.
>
>˛˛ >
>
>
> :readably bool >
> &environment var
>
> ˛ >
>

> >
> ⊲ Bind var to the lexical compilation environment.
>
>˛˛ :right-margin {int NIL} >
> sO
>
:˛:stream stream >
; &aux var ∗ ⊲ Bind var s as in let∗.
^ ∗standard-output∗
var

⊲ Print foo to stream and return foo, or print foo into


string, respectively, after dynamically setting printer vari-
ables corresponding to keyword parameters (∗print-bar ∗ be-
9.5 Control Flow
Fu sO
coming :bar ). (:stream keyword with write only.) (if test then [else NIL ])
ˆ ˜ ⊲ Return values of then if test returns T; return values of
Fu
^ foo parenthesis T [noop] )
(pprint-fill stream else otherwise.
Fu ˆ ˜
^ foo parenthesis T [noop [n 16 ]] )
(pprint-tabular stream M P
Fu ˆ ˜ (cond (test then ∗ test )∗ )
^ foo parenthesis T [noop] )
(pprint-linear stream ⊲ Return the values of the first then ∗ whose test returns T;
⊲ Print foo to stream. If foo is a list, print as many elements return NIL if all tests return NIL.
per line as possible; do the same in a table with a column
M ff
width of n ems; or print either all elements on one line or when P
each on its own line, respectively. Return NIL. Usable with ( M test foo ∗ )
Fu unless
format directive ˜//. ⊲ Evaluate foos and return their values if test returns T or
8˛ ff9 NIL, respectively. Return NIL otherwise.
<˛˛ :prefix string = ( )
M
^ list ˛˛ :per-line-prefix string  ff
(pprint-logical-block (stream ) M d∗ )
(key P ˆ otherwise P ˜
:˛ ; (case test ( foo ∗ )∗ ( bar ∗ ) NIL )
:suffix string "" d
key T
d ∗ )∗ formP∗ )
(declare decl ⊲ Return the values of the first foo ∗ one of whose keys is
⊲ Evaluate forms, which should print list, with stream lo- eql test. Return values of bar s if there is no matching key.
cally bound to a pretty printing stream which outputs to ( )
the original stream. If list is in fact not a list, it is printed M ff
ecase d∗ )
(key P
Fu
by write. Return NIL. ( M test ( d foo ∗ )∗ )
ccase key
M
⊲ Return the values of the first foo ∗ one of whose keys is
(pprint-pop) eql test. Signal non-correctable/correctable type-error and
⊲ Take next element off list. If there is no remaining return NIL if there is no matching key.
var var
tail of list, or ∗print-length∗ or ∗print-circle∗ indicate M
printing should end, send element together with an ap- (and form ∗ T )
propriate indicator to stream. ⊲ Evaluate forms from left to right. Immediately return
8 9 NIL if one form’s value is NIL. Return values of last form
>:line
>
<
>
>
= otherwise.
Fu :line-relative ^ ∗standard-output∗
(pprint-tab c i [stream var ]) M
>:section
> >
> (or form ∗ NIL )
: ;
:section-relative ⊲ Evaluate forms from left to right. Immediately return
⊲ Move cursor forward to column number c + ki, k ≥ 0 primary value of first non-NIL-evaluating form, or all values
being as small as possible. if last form is reached. Return NIL if no form returns T.
 ff
Fu :block ˆ ˜
(pprint-indent ^ ∗standard-output∗
n stream var ) sO
(progn form ∗ NIL )
:current
⊲ Specify indentation for innermost logical block rel- ⊲ Evaluate forms sequentially. Return values of last form .
ative to leftmost position/to current position. Return sO
(multiple-value-prog1 form-r form ∗ )
NIL. M
M (prog1 form-r form ∗ )
M
(pprint-exit-if-list-exhausted) (prog2 form-a form-r form ∗ )
⊲ If list is empty, terminate logical block. Return NIL ⊲ Evaluate forms in order. Return values/primary value,
otherwise. respectively, of form-r .

34 19
Common Lisp Quick Reference Common Lisp Quick Reference
sO ff ˛ ff∗
let ˛name n/d ⊲ The ratio n
.
( sO ( ˛˛ d ∗ )∗ formP∗ )
) (declare decl d
let∗ (name [value NIL ])
n ˆ ˜ ˆ ˜ o
⊲ Evaluate forms with names lexically bound (in parallel [m].n {S F D L E}x E0 m .[n] {S F D L E}x
or sequentially, respectively) to values. Return values of
forms. ⊲ m.n · 10x as short-float, single-float, double-float,
long-float, or the type from ∗read-default-float-format∗.
 M ff ˛ ff∗  ff
prog ˛name c ∗
d ∗ )∗ tag
Fu
( M ( ˛˛ ) (declare decl ) #C(a b) ⊲ (complex a b), the complex number a + bi.
prog∗ (name [value NIL ]) form
sO sO
⊲ Evaluate tagbody-like body with names lexically bound #’foo ⊲ (function foo); the function named foo.
(in parallel or sequentially, respectively) to values. Return
M
NIL or explicitly returned values. Implicitly, the whole form #nAsequence ⊲ n-dimensional array.
sO
is a block named NIL.
sO P
#[n](foo ∗ )
(progv symbols values form ∗ ) ⊲ Vector of some (or n) foos filled with last foo if necessary.
⊲ Evaluate forms with locally established dynamic bind-
ings of symbols to values or NIL. Return values of form s. #[n]∗b ∗
sO
⊲ Bit vector of some (or n) bs filled with last b if necessary.
(unwind-protect protected cleanup ∗ )
⊲ Evaluate protected and then, no matter how control #S(type {slot value}∗ ) ⊲ Structure of type.
leaves protected , cleanups. Return values of protected .
#Pstring ⊲ A pathname.
M
d ∗ )∗ formP∗ )
(destructuring-bind destruct-λ bar (declare decl
#:foo ⊲ Uninterned symbol foo.
⊲ Evaluate forms with variables from tree destruct-λ bound
to corresponding elements of tree bar , and return their #.form ⊲ Read-time value of form .
values. destruct-λ resembles macro-λ (section 9.4), but
var
without any &environment clause. ∗read-eval∗ T ⊲ If NIL, a reader-error is signalled at #..
M
(multiple-value-bind (d d ∗ )∗
var ∗ ) values-form (declare decl #integer = foo ⊲ Give foo the label integer.
P
body-form ∗ )
⊲ Evaluate body-forms with var s lexically bound to the re- #integer # ⊲ Object labelled integer.
turn values of values-form. Return values of body-form s.
#< ⊲ Have the reader signal reader-error.
sO P
(block name form ∗ )
#+feature when-feature
⊲ Evaluate forms in a lexical environment, and return their
sO #–feature unless-feature
values unless interrupted by return-from.
⊲ Means when-feature if feature is T; means unless-feature
var
sO
(return-from foo [result NIL ]) if feature is NIL. feature is a symbol from ∗features∗, or
M ∗
({and or} feature ), or (not feature).
(return [result NIL ])
sO
⊲ Have nearest enclosing block named foo/named NIL, re- var
∗features∗
spectively, return with values of result. ⊲ List of symbols denoting implementation-dependent fea-
sO
c form}∗ ) tures.
(tagbody {tag
⊲ Evaluate forms in a lexical environment. tags (symbols |c ∗ |; \c
or integers) have lexical scope and dynamic extent, and are ⊲ Treat arbitrary character(s) c as alphabetic preserving
sO
targets for go. Return NIL. case.
sO
c
(go tag)
sO
⊲ Within the innermost possible enclosing tagbody, jump 13.4 Printer
to a tag eql tag. 8 Fu 9
sO P
>prin1
>
< Fu
>
>
=
(catch tag form ∗ ) print ^ ∗standard-output∗
( Fu foo [stream var ])
⊲ Evaluate forms and return their values unless interrupted >
>pprint>
sO : Fu > ;
by throw. princ
Fu Fu
⊲ Print foo to stream readably, readably between a newline
sO Fu
(throw tag form) and a space, readably after a newline, or human-readably
sO Fu Fu
⊲ Have the nearest dynamically enclosing catch with a tag without any extra characters, respectively. prin1, print and
Fu Fu
eq tag return with the values of form. princ return foo.
Fu Fu
(sleep n) ⊲ Wait n seconds, return NIL. (prin1-to-string foo)
Fu
(princ-to-string foo)
Fu
⊲ Print foo to string readably or human-readably, respec-
9.6 Iteration tively.
M ff  ff∗ gF
do var ˆ ^
(print-object object stream)
( M ( ˜ ) (stop resultP∗ ) (declare decl
d ∗ )∗
do∗ (var start [step] ) ⊲ Print object to stream. Called by the Lisp printer.
 ff∗
c
tag ˛ ff
) ˛
form M
^ ˛˛:type bool NIL
(print-unreadable-object (foo stream
P
) form ∗ )
sO
⊲ Evaluate tagbody-like body with var s successively bound :identity bool NIL
according to the values of the corresponding start and step ⊲ Enclosed in #< and >, print foo by means of forms to
forms. var s are bound in parallel/sequentially, respectively. stream. Return NIL.
Stop iteration when stop is T. Return values of result ∗ . Fu
sO
Implicitly, the whole form is a block named NIL. ^ ∗standard-output∗
(terpri [stream var ])
⊲ Output a newline to stream. Return NIL.
M
d ∗ )∗ {tag
(dotimes (var i [result NIL ]) (declare decl c form}∗ )
Fu
sO
⊲ Evaluate tagbody-like body with var successively bound ^ ∗standard-output∗
(fresh-line) [stream var ]
to integers from 0 to i − 1. Upon evaluation of result , var ⊲ Output a newline to stream and return T unless stream
sO
is i. Implicitly, the whole form is a block named NIL. is already at the start of a line.

20 33
Common Lisp Quick Reference Common Lisp Quick Reference

Fu M
^ stream
(read-sequence sequence ^ [:start start 0 ][:end end NIL ]) d ∗ )∗ {tag
(dolist (var list [result NIL ]) (declare decl c form}∗ )
sO
⊲ Replace elements of sequence between start and end with ⊲ Evaluate tagbody-like body with var successively bound
elements from binary or character stream. Return index of to the elements of list. Upon evaluation of result , var is
sO
sequence’s first unmodified element. NIL. Implicitly, the whole form is a block named NIL.
Fu
(readtable-case readtable ) :upcase
⊲ Case sensitivity attribute (one of :upcase, :downcase, 9.7 Loop Facility
:preserve, :invert) of readtable. setfable. M
(loop form ∗ )
ˆ ˜ ⊲ Simple Loop. If forms do not contain any atomic Loop
Fu
(copy-readtable from-readtable ∗readtable∗
var ^
[to-readtable NIL ] ) sO
⊲ Return copy of from-readtable . Facility keywords, evaluate them forever in an implicit block
named NIL.
ˆ M
Fu
^
(set-syntax-from-char to-char from-char to-readtable var (loop clause ∗ )
˜ ∗readtable∗
[from-readtable standard readtable ] ) ⊲ Loop Facility. For Loop Facility keywords see below and
⊲ Copy syntax of from-char to to-readtable. Return T. Figure 1.
var M sO
∗readtable∗ ⊲ Current readtable. named n NIL ⊲ Give loop’s implicit block a name.
 ff
var-s
var
∗read-base∗ 10 ⊲ Radix for reading integers and ratios. {with [d-type] = foo}+
(var-s ∗ )
 ff
var var-p
∗read-default-float-format∗ single-float {and [d-type] = bar }∗
(var-p ∗ )
⊲ Floating point format to use when not indicated in the where destructuring type specifier
number read. n  ff o has the form
d-type
˘ type ¯
fixnum float T NIL of-type
var
∗read-suppress∗ NIL (type ∗ )
⊲ If T, reader is syntactically more tolerant. ⊲ Initialize (possibly trees of) local variables var-s se-
ˆ ˜ quentially and var-p in parallel.
Fu  ff  ff
(set-macro-character char function non-term-p NIL [rt e ∗readtable∗
var ] ) ˘ var-s ¯+ ˘ var-p ¯∗
{for as} [d-type] and [d-type]
⊲ Make char a macro character associated with function (var-s ∗ ) (var-p ∗ )
of stream and char . Return T. ⊲ Begin of iteration control clauses. Initialize and step
Fu (possibly trees of) local variables var-s sequentially and
(get-macro-character char [rt ∗readtable∗
var ]) var-p in parallel. Destructuring type specifier d-type as
⊲ Reader macro function associated with char , and T if with with.
2
char is a non-terminating macro character. {upfrom from downfrom} start
Fu ˆ ⊲ Start stepping with start
(make-dispatch-macro-character char non-term-p NIL {upto downto to below above} form
˜
[rt ∗readtable∗
var ] ) ⊲ Specify form as the end value for stepping.
⊲ Make char a dispatching macro character. Return T. {in on} list
Fu ⊲ Bind var to successive elements/tails, respec-
(set-dispatch-macro-character char sub-char function tively, of list.
e ∗readtable∗
[rt var ]) by {step 1 function #’cdr }
⊲ Make function of stream, n, sub-char a dispatch function
⊲ Specify the (positive) decrement or increment or
of char followed by n, followed by sub-char . Return T.
the function of one argument returning the next
Fu
(get-dispatch-macro-character char sub-char [rt ∗readtable∗
var ]) part of the list.
⊲ Dispatch function associated with char followed by = foo [then bar foo ]
sub-char . ⊲ Bind var initially to foo and later to bar .
across vector
⊲ Bind var to successive elements of vector .
13.3 Character Syntax being {the each}
⊲ Iterate over a hash table or a package.
#| multi-line-comment ∗ |# {hash-key hash-keys} {of in} hash-table [using
; one-line-comment ∗ (hash-value value)]
⊲ Comments. There are stylistic conventions: ⊲ Bind var successively to the keys of
hash-table; bind value to corresponding values.
;;;; title ⊲ Short title for a block of code. {hash-value hash-values} {of in} hash-table [using
;;; intro ⊲ Description before a block of code. (hash-key key)]
⊲ Bind var successively to the values of
;; state ⊲ State of program or of following code.
hash-table; bind key to corresponding keys.
;explanation {symbol symbols present-symbol present-symbols
⊲ Regarding line on which it appears.
; continuation
external-symbol external-symbols} [{of in}
package ∗package∗
var ]
(foo ∗ [ . bar NIL ]) ⊲ List of foos with the terminating cdr bar .
⊲ Bind var successively to the accessible sym-
” ⊲ Begin and end of a string. bols, or the present symbols, or the external
symbols respectively, of package.
sO
’foo ⊲ (quote foo); foo unevaluated. {do doing} form +
⊲ Evaluate forms in every iteration.
`([foo] [,bar ] [,@baz ] [,.]
quux ] [bing])
sO {if when unless} test i-clause {and j-clause}∗ [else
⊲ Backquote. quote foo and bing; evaluate bar and splice
k-clause {and l-clause}∗ ] [end]
the lists baz and quux into their elements. When nested,
⊲ If test returns T, T, or NIL, respectively, evaluate
outermost commas inside the innermost backquote expres-
i-clause and j-clauses; otherwise, evaluate k-clause and
sion belong to this backquote.
l-clauses.
Fu
#\c ⊲ (character "c"), the character c. it ⊲ Inside i-clause or k-clause: value of test .
return {form it}
#Bn; #On; n.; #Xn; #r Rn ⊲ Return immediately, skipping any finally parts, with
⊲ Integer of radix 2, 8, 10, 16, or r ; 2 ≤ r ≤ 36. values of form or it.

32 21
Common Lisp Quick Reference Common Lisp Quick Reference

13 Input/Output

)
9∗
>
>
>
>
>
>
>
>
when test Ci {and Cj } [else Ck {and Cl } ][end] > >
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
=
>
>
>
>
>
>
>
C0 >
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
;
13.1 Predicates
Fu
(streamp foo)
Fu
(pathnamep foo) ⊲ T if foo is of indicated type.

Fu
(readtablep foo)
Fu
(input-stream-p stream)
Fu

[type]
(output-stream-p stream)
Fu
(interactive-stream-p stream)
Fu
num ] (open-stream-p stream)
list]

⊲ Return T if stream is for input, for output, interactive, or


open, respectively.

[into

[into

Fu
(pathname-match-p path wildcard )

⊲ T if path matches wildcard .


form

form

T2
Fu
it

(wild-pathname-p path {:host :device :directory :name :type


and Fi > > maximizing> it

˜

form
+

:version NIL} )
it 9
=
;
9
>
>
sum[ming] > >
>
=

>
>
minimize > >
;
form

always test
form

num
append[ing]

⊲ Return T if indicated component in path is wildcard. (NIL


collect[ing]

minimizing
nconc[ing]
count[ing]

maximize

indicates any component.)


9
>
>
>
=
>
>
never > ;

9
=
;

initially
do[ing]

: thereis
repeat
return
unless

finally

while
until

13.2 Reader
if
8
9∗ >
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
; >>
>
>

 Fu ff
y-or-n-p
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
=

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

( Fu [control arg ∗ ])

yes-or-no-p
o

⊲ Ask user a question and return T or NIL depending on


Fu
their answer. See p. 35, format, for control and arg s.
M P
(with-standard-io-syntax form ∗ )
n

⊲ Evaluate forms with standard behaviour of reader and


F0

printer. Return values of form s.


9
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
=
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
;
˜

 Fu ff
)]

)]

∗package∗

read ˆ ˆ
v

( Fu ^ ∗standard-input∗
stream var eof-err T
(hash-key
(hash-value

read-preserving-whitespace
˜˜
var

[eof-val NIL [recursive NIL ]] )


package

⊲ Read printed representation of object.


1 ]

ˆ ˆ
step

Fu
[using

(read-from-string
8˛ string eof-error T eof-val
9 NIL
[using

˛
ˆ<˛:start start 0 =˜˜˜

[by

of

˛:end end NIL


; in

˛ )
hash

:˛ ;
9
>
>
form > >
>
>
>
>
>
=
>
>
>
>
˜ >>
>
>
>
;

:preserve-whitespace bool NIL


hash


˜
[d-type] = bar }∗

⊲ Return object read from string and zero-indexed position


external-symbol[s]
form

present-symbol[s]

2
of
 ff

in

of next character.
of

in
9
=
;

ˆ ˜
hash-value[s]
below

9
=
;

Fu
(read-delimited-list char stream ^ ∗standard-input∗
var [recursive NIL ] )
upto

>hash-key[s]
form
downto

>symbol[s]
#’cdr
above
to

⊲ Continue reading until encountering char . Return list of


8
<
:

objects read. Signal error if no char is found in stream.


to
ˆ

<in list [by function


downto

]
above8
<
:

ˆ ˆ
˜

foo
(var )

Fu
^ ∗standard-input∗
start 0

(read-char stream eof-err T [eof-val NIL


var
8
>
>
>
>
>
>
<
>
>
>
>
>
>
:

˜˜
bar
start
var

[recursive NIL ]] )

>across vector

each
[then

⊲ Return next character from stream.


the
start

downfrom
upfrom
[d-type] = foo {and

ˆ ˆ

from

Fu
^ ∗standard-input∗
(read-char-no-hang stream var eof-error T [eof-val NIL
foo

being

˜˜
from

> ff

[recursive NIL ]] )

∗ [d-type] on
=
ˆ

⊲ Next character from stream or NIL if none is available.


8
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
:

Fu ˆ ˆ ˆ
(peek-char mode NIL stream^ ∗standard-input∗
var eof-error T [eof-val NIL
˜˜˜
[recursive NIL ]] )

⊲ Next, or if mode is T, next non-whitespace character,


(var )
(var )

or if mode is a character, next instance of it, from stream


var
var

without removing it there.



Fu
^ ∗standard-input∗
< ff
with

(unread-char character [stream var ])


T1
(loop [named n NIL ] for

Fu
as

⊲ Put last read-chared character back into stream; return


8
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
:

NIL.
Fu ˆ ˜
^ eof-err T [eof-val NIL ] )
(read-byte stream
⊲ Read next byte from binary stream.
Fu ˆ ˆ
Figure 1: Loop Facility, ^ ∗standard-input∗
(read-line stream var eof-err T [eof-val NIL
Overview. ˜˜
[recursive NIL ]] )
⊲ Return a line of text from stream and T if line has been
2
ended by end of file.

22 31
Common Lisp Quick Reference Common Lisp Quick Reference

{collect collecting} {form it} [into list]


⊲ Collect values of form or it into list. If no list is
given, collect into an anonymous list which is returned
after termination.

unbound-variable
reader-error

unbound-slot
end-of-file

undefined-function

floating-point-invalid-operation
style-warning

simple-warning
{append appending nconc nconcing} {form it} [into list]
simple-condition

simple-error ⊲ Concatenate values of form or it, which should be


warning

Fu Fu

floating-point-underflow
lists, into list by the means of append or nconc, respec-

floating-point-overflow
floating-point-inexact
tively. If no list is given, collect into an anonymous list
which is returned after termination.
print-not-readable {count counting} {form it} [into n] [type]

division-by-zero
⊲ Count the number of times the value of form or of it
program-error

package-error
storage-condition
simple-type-error

control-error

stream-error
is T. If no n is given, count into an anonymous variable

arithmetic-error
parse-error
type-error

which is returned after termination.


cell-error
file-error
{sum summing} {form it} [into sum] [type]
⊲ Calculate the sum of the primary values of form or of
it. If no sum is given, sum into an anonymous variable
error

which is returned after termination.


{maximize maximizing minimize minimizing} {form it} [into
˜
float lower-limit ∗ [upper-limit ∗ ]

max-min] [type]
serious-condition

⊲ Determine the maximum or minimum, respectively,


˜

˜
number
complex [type ∗ ]
˜

signed-byte [size ∗ ] fixnum bignum


short-float lower-limit ∗ [upper-limit ∗ ]

double-float lower-limit ∗ [upper-limit ∗ ]

long-float lower-limit ∗ [upper-limit ∗ ]

rational lower-limit ∗ [upper-limit ∗ ]

integer lower-limit ∗ [upper-limit ∗ ]


]


of the primary values of form or of it. If no max-min

bit
[upper-limit
[upper-limit

is given, use an anonymous variable which is returned


condition

after termination.
unsigned-byte [size ∗ ]
{initially finally} form +
⊲ Evaluate forms before begin, or after end, respec-
logical-pathname

tively, of iterations.

lower-limit
lower-limit

repeat num
M
⊲ Terminate loop after num iterations; num is evalu-
pathname

ated once.
ˆ

{while until} test


ˆ

ˆ
ˆ

⊲ Continue iteration until test returns NIL or T, respec-


standard-generic-function

single-float
real

tively.
ratio

{always never} test


M
˜

compiled-function

⊲ Terminate loop returning NIL and skipping any finally


function arg-types [value-types]

generic-function

parts as soon as test is NIL or T, respectively. Otherwise


stream

M
continue loop with its default return value set to T.
thereis test
M
⊲ Terminate loop when test is T and return value of test,
M
string-stream
broadcast-stream
file-stream

synonym-stream
two-way-stream

echo-stream
concatenated-stream

skipping any finally parts. Otherwise continue loop with


its default return value set to NIL.
M
˜

(loop-finish)
simple-array type ∗ [rank ∗ (dimension ∗ )]

M
⊲ Terminate loop immediately executing any finally
ˆ

clauses and returning any accumulated results.


˜
array type ∗ [rank ∗ (dimension ∗ )]
sequence

10 CLOS
cons car-type ∗ [cdr-type ∗ ]

simple-base-string [size ∗ ]

simple-bit-vector [size ∗ ]
˜

10.1 Classes
vector type ∗ [size ∗ ]

simple-vector [size ∗ ]
simple-string [size ∗ ]
base-string [size ∗ ]
standard-char

Fu
bit-vector [size ∗ ]
extended-char

(slot-exists-p foo bar ) ⊲ T if foo has a slot bar .


base-char

list

string [size ∗ ]

Fu
(slot-boundp instance slot) ⊲ T if slot in instance is bound.
ˆ

M
(defclass foo (superclass ∗ standard-object )
ˆ
ˆ

8 9∗
> slot
>
> 8˛ ∗ 9> >
>
>
> > ˛ {:reader reader
 } ff > >
>
> > ˛ > >
character

>
> >
> ˛ writer >
> >
>
>
> >˛{:writer
> }∗ >
> >
>
>
> >
> ˛ (setf writer ) >
> >
>
keyword

> > > >


boolean

standard-method

>
> >
> ˛ ∗ >
> >
>
structure-object
null

structure-class

< >˛{:accessor accessor }ff > =


standard-object

standard-class

method-combination

>
<˛  >
=
built-in-class
random-state

( ˛ :instance )
>
> (slot ˛ :allocation :instance )>
>
> > ˛ :class > >
hash-table

> > > >


readtable

>
> >
> ˛ >
> >
>˛{:initarg :initarg-name}∗ >>
package

> >
method

> > > >


symbol

restart

>
> >
> ˛ >
> >
>
atom

>
> >
>˛˛ :initform form >
>> >
>
> >
> >
> >
>
> :˛˛
> :type type ;>
>
class

: ;
8˛ :documentation slot-doc 9
<˛˛(:default-initargs {name value}∗ )=
T

˛(:documentation class-doc) )
:˛˛ ;
(:metaclass name standard-class )
⊲ Define, as a subclass of superclass es, class foo. In a new
Figure 2: Precedence Order of System Classes ( ), Classes ( ),
instance i , a slot ’s value defaults to form unless set via
Types ( ), and Condition Types ( ).
:initarg-name; it is readable via (reader i) or (accessor
i), and writeable via (writer i value) or (setf (accessor
i) value). With :allocation :class, slot is shared by all in-
stances of class foo.

30 23
Common Lisp Quick Reference Common Lisp Quick Reference

Fu ˆ ˜ Fu
(find-class symbol errorp T [environment ] ) (type-error-datum condition)
Fu
⊲ Return class named symbol . setfable. (type-error-expected-type condition)
⊲ Object which caused condition of type type-error, or its
gF
(make-instance class {:initarg value}∗ other-keyarg ∗ ) expected type, respectively.
⊲ Make new instance of class . Fu
(simple-condition-format-control condition)
Fu
gF (simple-condition-format-arguments condition )
(reinitialize-instance instance {:initarg value}∗ other-keyarg ∗ ) Fu Fu
⊲ Return format control or list of format arguments, re-
⊲ Change local slots of instance according to initargs. spectively, of condition .
Fu var
(slot-value foo slot) ⊲ Return value of slot in foo . setfable. ∗break-on-signals∗ NIL
⊲ Condition type debugger is to be invoked on.
Fu
(slot-makunbound instance slot ) var
∗debugger-hook∗ NIL
⊲ Make slot in instance unbound. ⊲ Function of condition and function itself. Called before
M ff debugger.
d (d
with-slots ({slot d ∗)
var slot)}
( M d ∗ )∗
instance (declare decl
with-accessors ((d \ ) )
var accessor ∗
P∗
form )
⊲ Return values of form s after evaluating them in a lexical
12 Types and Classes
environment with slots of instance visible as setfable slot s
For any class, there is always a corresponding type of the same
or var s/with accessor s of instance visible as setfable var s.
name.
gF Fu
(class-name class) (typep foo type [environment NIL ]) ⊲ T if foo is of type.
gF ⊲ Get/set name of class .
((setf class-name) new-name class) Fu
(subtypep type-a type-b [environment])
Fu ⊲ Return T if type-a is a recognizable subtype of type-b,
(class-of foo) ⊲ Class foo is a direct instance of.
and NIL if the relationship could not be determined.
2
gF
^ new-class {:initarg value}∗ other-keyarg ∗ )
(change-class instance sO
d form)
(the type ⊲ Declare values of form to be of type.
⊲ Change class of instance to new-class. Fu
(coerce object type) ⊲ Coerce object into type.
gF
(make-instances-obsolete class)  ff
ˆ ˜
⊲ Update instances of class.
M
d a-formP∗ )∗ ( otherwise b-form NILP∗ ) )
(typecase foo (type
T
 gF ff ⊲ Return values of the a-form s whose type is foo of. Return
initialize-instance (instance)
( gF values of b-form s if no type matches.
update-instance-for-different-class previous current
M ff
{:initarg value}∗ other-keyarg ∗ ) ctypecase
( M d formP∗ )∗ )
foo (type
⊲ Its primary method sets slots on behalf of etypecase
gF gF gF
make-instance/of change-class by means of shared-initialize. ⊲ Return values of the form s whose type is foo of. Sig-
gF
nal correctable/non-correctable error, respectively if no type
(update-instance-for-redefined-class instances added-slots matches.
discarded-slots property-list {:initarg value}∗ Fu
other-keyarg ∗ ) (type-of foo) ⊲ Type of foo .
⊲ Its primary method sets slots on behalf of M
gF gF (check-type place type [string {a an} type ])
make-instances-obsolete by means of shared-initialize.
⊲ Signal correctable type-error if place is not of type. Re-
gF
(allocate-instance class {:initarg value}∗ other-keyarg ∗ ) turn NIL.
⊲ Return uninitialized instance of class. Called by Fu
(stream-element-type stream) ⊲ Return type of stream objects.
gF
make-instance.
Fu
 ff (array-element-type array ) ⊲ Element type array can hold.
gF slots
(shared-initialize instance {:initarg value}∗ other-keyarg ∗ ) Fu
(upgraded-array-element-type type [environment NIL ])
T
⊲ Fill instance’s slots using initargs and :initform forms. ⊲ Element type of most specialized array capable of holding
elements of type.
8 9
>
>setf >
> M
d ∗ )∗ [doc]
d formP∗ )
gF
<
slot-boundp
= (deftype foo (macro-λ∗ ) (declare decl
(slot-missing class object slot [value]) ⊲ Define type foo which when referenced as (foo argc ∗ ) ap-
>slot-makunbound>
>
: >
; plies expanded forms to args returning the new type. For
slot-value
(macro-λ∗ ) see p. 18 but with default value of ∗ instead of
⊲ Called in case of attempted access to missing slot . Its sO
NIL. form s are enclosed in an implicit block named foo.
primary method signals error.
gF (eql foo)
(slot-unbound class instance slot ) ⊲ Specifier for a type comprising foo or foos.
Fu (member foo ∗ )
⊲ Called by slot-value in case of unbound slot . Its primary
method signals unbound-slot. (satisfies predicate)
⊲ Type specifier for all objects satisfying predicate.

(mod n) ⊲ Type specifier for all non-negative integers < n.


10.2 Generic Functions
Fu
(not type) ⊲ Complement of type.
(next-method-p)
⊲ T if enclosing method has a next method. (and type ∗ T) ⊲ Type specifier for intersection of types.

 ff  ff∗ (or type ∗ NIL )


⊲ Type specifier for union of types.
M foo ˆ var ˜
(defgeneric (required-var ∗ &optional ˆ ˜
(setf foo) (var ) (values &optional type ∗ [&rest other-args ] )
type ∗
 ff∗ ⊲ Type specifier for multiple values.
ˆ ˜ˆ var
&rest var &key
(var (:key var )) ∗ ⊲ As a type argument (cf. Figure 2): no restriction.
˜
[&allow-other-keys] )

24 29
Common Lisp Quick Reference Common Lisp Quick Reference
 ff 8˛ 9
M restart P > ˛(:argument-precedence-order required-var + ) >
(with-simple-restart ( control arg ∗ ) form ∗ ) >
>
>
˛
˛(declare (optimize arg ) ) ∗ + >
>
>
NIL >
> ˛ >
>
⊲ Return values of form s unless restart is called during >
> ˛ \ >
>
Fu
<˛(:documentation string) =
their evaluation. In this case, describe restart using format ˛(:generic-function-class class ) )
> ˛ standard-generic-function
>
control and args (see p. 35) and return NIL and T. >˛˛(:method-class class standard-method )
> >
>
2 >
> >
>
>
> ˛ ∗ >
>
8˛ 9 >˛(:method-combination c-type standard c-arg )
: >
;
˛ ˛(:method defmethod-args)∗
>˛:interactive
>
<  arg-function > >
M ˛ report-function = ⊲ Define generic function foo. defmethod-args resemble
(restart-case form (foo (ord-λ∗ ) ˛˛:report M
>
> string "foo" > those of defmethod. For c-type see section 10.3.
:˛˛ >
;
:test test-function T  ff
d ∗ )∗ restart-form ∗ )∗ )
(declare decl
P Fu foo
(ensure-generic-function
⊲ Evaluate form with dynamically established restarts foo. (setf foo)
Fu 8˛ 9
Return values of form or, if by (invoke-restart foo arg ∗ ) > ˛:argument-precedence-order required-var + >
>˛˛:declare (optimize arg ∗ )+
> >
>
one restart foo is called, use string or report-function (of >
> >
>
>
> ˛ >
>
a stream) to print a description of restart foo and return >
> ˛:documentation string >
>
<˛ =
the values of its restart-form s. arg-function supplies ap- ˛:generic-function-class class
Fu ˛ )
propriate args if foo is called by invoke-restart-interactively. >
> ˛:method-class class >
>
>
> ˛ ∗ >
>
If (test-function condition ) returns T, foo is made visible >˛:method-combination c-type c-arg
> >
>
>
> ˛ >
>
under condition. arg ∗ matches (ord-λ∗ ); see p. 16 for the :˛˛:lambda-list lambda-list
> >
;
latter. :environment environment
 ff ⊲ Define or modify generic function foo.
M \
restart :generic-function-class and :lambda-list have to be compat-
(restart-bind (( restart-function
8˛ NIL 9 ible with a pre-existing generic function or with existing
˛
<˛:interactive-function function = methods, respectively. Changes to :method-class do not
P
˛:report-function function )∗ ) form ∗ ) propagate to existing methods. For c-type see section 10.3.
:˛˛ ;
:test-function function 8 9
⊲ Return values of form s evaluated with restart s dynami-  ff > > :before > >
< =
cally bound to restart-functions. M foo :after
(defmethod [ primary method ]
Fu (setf foo) > > :around >
>
(invoke-restart restart arg ∗ ) : ∗;
Fu qualifier
(invoke-restart-interactively restart ) 8 9∗
<var  ff= ˆ
⊲ Call function associated with restart with arguments
( class &optional
given or prompted for, respectively. If restart function re- :(spec-var );
(eql bar )
turns, return its values.  ff∗
var ˆ ˜ ˆ
 Fu ff ˜ [&rest var ] &key
compute-restarts (var init [supplied-p] )
( Fu [condition]) 8 9∗
find-restart name <var ff = ˜
⊲ Return list of all restarts, or innermost restart name, var ˆ ˜ [&allow-other-keys]
:( init [supplied-p] );
respectively, out of those either associated with condition (:key var )
or un-associated at all; or, without condition , out of all  ff∗ (˛˛ )
ˆ var ˜ ˛(declare decl d ∗ )∗ P
restarts. Return NIL if search is unsuccessful. &aux ) ˛ form ∗ )
(var [init]) d
˛doc
Fu
(restart-name restart) ⊲ Name of restart . ⊲ Define new method for generic function foo. spec-var s
8 Fu 9 specialize to either being of class or being eql bar , re-
>abort > spectively. On invocation, var s and spec-var s of the new
>
> Fu >
>
<muffle-warning
Fu
= method act like parameters of a function with body form ∗ .
sO
( continue [condition NIL ]) forms are enclosed in an implicit block foo. Applicable
>
> Fu >
:store-value
> value>
>
; qualifier s depend on the method-combination type; see sec-
Fu
use-value value tion 10.3.
⊲ Transfer control to innermost applicable restart with  gF ff
same name (i.e. abort, . . . , continue . . . ) out of those add-method
( gF generic-function method )
either associated with condition or un-associated at all; or, remove-method
without condition , out of all restarts. If no restart is found, ⊲ Add (if necessary) or remove (if any) method to/from
Fu Fu
signal control-error for abort and muffle-warning, or return generic-function.
NIL for the rest. gF
M P∗
(find-method generic-function qualifiers specializers [error T ])
(with-condition-restarts condition restarts form ) ⊲ Return suitable method, or signal error.
⊲ Evaluate forms with restarts dynamically associated
gF
with condition. Return values of form s. (compute-applicable-methods generic-function args)
Fu ⊲ List of methods suitable for args, most specific first.
(arithmetic-error-operation condition)
Fu Fu
(arithmetic-error-operands condition) (call-next-method arg ∗ current args )
⊲ List of function or of its operands respectively, used in ⊲ From within a method, call next method with args; re-
the operation which caused condition . turn its values.
Fu
(cell-error-name condition ) gF
(no-applicable-method generic-function arg ∗ )
⊲ Name of cell which caused condition.
⊲ Called on invocation of generic-function on args if there
Fu
(unbound-slot-instance condition) is no applicable method. Default method signals error.
⊲ Instance with unbound slot which caused condition .  Fu ff
invalid-method-error method
Fu ( Fu control arg ∗ )
(print-not-readable-object condition) method-combination-error
⊲ The object not readably printable under condition. ⊲ Signal error on applicable method with invalid qualifiers,
Fu
or on method combination. For control and arg s see format,
(package-error-package condition) p. 35.
Fu
(file-error-pathname condition )
Fu gF
(stream-error-stream condition ) (no-next-method generic-function method arg ∗ )
⊲ Package, path, or stream, respectively, which caused the ⊲ Called on invocation of call-next-method when there is
condition of indicated type. no next method. Default method signals error.

28 25
Common Lisp Quick Reference Common Lisp Quick Reference

gF
(function-keywords method )
⊲ Return list of keyword parameters of method and T if
11 Conditions and Errors
2
other keys are allowed. For standardized condition types cf. Figure 2 on page 30.
gF M
(method-qualifiers method ) ⊲ List of qualifiers of method . (define-condition foo (parent-type ∗ condition )
8 9∗
> slot
>
> 8˛ ∗ 9> >
>
>
> > ˛{:reader  reader } ff > >
>
>
> >
> ˛ >
> >
>
10.3 Method Combination Types >
>
>
> ˛
>˛{:writer
>
writer
}∗ >
>
>
>
>
>
>
> >
> ˛ (setf writer ) >
> >
>
standard >
> >
> ˛ >
> >
>
>
< >
>˛{:accessor accessor }∗ >
> >
=
⊲ Evaluate most specific :around method supplying the val- >
<˛  ff >
=
( ˛ :instance )
ues of the generic function. From within this method, >
> (slot ˛ :allocation )
:instance > >>
Fu >
> >˛
> :class > >
>
call-next-method can call less specific :around methods if >
> >
> ˛ ∗ >
> >
>
there are any. If not, or if there are no :around methods
>
>
> >˛˛{:initarg :initarg-name}
>
>
>
>>
> >
>
>
> >
> ˛ :initform form >
> >
>
at all, call all :before methods, most specific first, and the >
> >
>˛ >>
> >
> > > >
most specific primary method which supplies the values of
>
: :˛˛:type type
> >
;> ;
Fu
8˛ :documentation slot-doc 9
the calling call-next-method if any, or of the generic func- ˛(:default-initargs {name value}∗ )>
>
>
tion; and which can call less specific primary methods via <˛˛ >
=
Fu
call-next-method. After its return, call all :after methods, ˛(:documentation
 condition-doc)
ff )
> ˛ string >
least specific first. >
:˛˛(:report ) >
;
report-function
and or append list nconc progn max min + ⊲ Define, as a subtype of parent-types, condition type foo.
⊲ Simple built-in method-combination types; have the In a new condition, a slot ’s value defaults to form unless set
same usage as the c-types defined by the short form of via :initarg-name; it is readable via (reader i) or (accessor
M
define-method-combination. i), and writeable via (writer i value) or (setf (accessor i)
M
value). With :allocation :class, slot is shared by all condi-
(define-method-combination
8˛ c-type 9 tions of type foo. A condition is reported by string or by
<˛˛:documentation s\ tring = report-function of arguments condition and stream.
˛:identity-with-one-argument bool NIL )
:˛˛ ;
Fu
(make-condition type {:initarg-name value}∗ )
:operator operator c-type
⊲ Return new condition of type .
⊲ Short Form. Define new method-combination c-type.
8 Fu 9 8 9
In a generic function using c-type, evaluate most spe- <signal = <condition =
cific :around method supplying the values of the generic Fu ∗
Fu ( warn type {:initarg-name value} )
function. From within this method, call-next-method : Fu ; : ;
error control arg ∗
can call less specific :around methods if there are any. ⊲ Unless handled, signal as condition, warning or error,
If not, or if there are no :around methods at all, respectively, condition or a new condition of type or,
return from the calling call-next-method or from the Fu
with format control and arg s (see p. 35), simple-condition,
generic function, respectively, the values of (operator Fu
simple-warning, or simple-error, respectively. From signal
(primary-method gen-arg ∗ )∗ ), gen-arg ∗ being the argu- Fu
and warn, return NIL.
ments of  the generic function.ff The primary-method s are 8 9
ˆ :most-specific-first ˜ <condition continue-arg ∗ =
ordered (specified as Fu
:most-specific-last :most-specific-first (cerror continue-control type {:initarg-name value} ) ∗
M : ;
c-arg in defgeneric). Using c-type as the qualifier in control arg ∗
M
defmethod makes the method primary. ⊲ Unless handled, signal as correctable error condition or a
Fu
M ∗
new condition of type or, with format control and arg s (see
(define-method-combination
8 9 c-type (ord-λ ) ((group
Fu
p. 35), simple-error. In the debugger, use format arguments
<∗ ˆ ˜ = continue-control and continue-args to tag the continue op-
(qualifier ∗ ∗ ) tion. Return NIL.
: ;
8predicate
˛ 9 M P
> ˛:description control > (ignore-errors form ∗ )
>
<˛˛  ff >
= ⊲ Return values of form s or, in case of errors, NIL and the
˛:order :most-specific-first )∗ )
> ˛ :most-specific-last :most-specific-first
> condition.

: >
; 2
˛:required bool Fu
8˛ ∗ 9 (invoke-debugger condition )
>˛˛(:arguments method-combination-λ )>
> > ⊲ Invoke debugger with condition.
<˛(:generic-function symbol ) =
P
˛ body ∗ ) 8 9
> d )
˛(declare decl ∗ ∗
> <condition continue-arg ∗ =˜
> ˛
:˛d >
; M ˆ ∗ ∗
(assert test (place ) [ type {:initarg-name value} ] )
doc
: ;
⊲ Long Form. Define new method-combination c-type. A control arg ∗
call to a generic function using c-type will be equivalent to ⊲ If test, which may depend on places, returns NIL, signal
a call to the forms returned by body ∗ with ord-λ∗ bound to as correctable error condition or a new condition of type or,
M Fu
c-arg ∗ (cf. defgeneric), with symbol bound to the generic with format control and args (see p. 35), error. When using
function, with method-combination-λ∗ bound to the argu- the debugger’s continue option, places can be altered before
ments of the generic function, and with groups bound to re-evaluation of test. Return NIL.
lists of methods. An applicable method becomes a mem- M
ber of the leftmost group whose predicate or qualifier s d ∗ )∗ condition-form ∗ )∗
(handler-case foo (type ([var ]) (declare decl
P
M
match. Methods can be called via call-method. Lambda d ∗ )∗ formP∗ )])
[(:no-error (ord-λ∗ ) (declare decl
lists (ord-λ ) and (method-combination-λ∗ ) according to

⊲ If, on evaluation of foo, a condition of type is signalled,
ord-λ on p. 16, the latter enhanced by an optional &whole evaluate matching condition-forms with var bound to the
argument. condition, and return their values. Without a condition,
( ) ( )∗ bind ord-λs to values of foo and return values of form s or,
M \
method \
ˆ next-method ˜ without a :no-error clause, return values of foo. See p. 16
(call-method ( ) )
M
[)
(make-method form
M
(make-method form [) for (ord-λ∗ ).
⊲ From within an effective method form, call method with M
(handler-bind ((condition-type handler-function)∗ ) form ∗ )
P

the arguments of the generic function and with information ⊲ Return values of form s after evaluating them with
about its next-methods; return its values. condition-types dynamically bound to their respective
handler-functions of argument condition.

26 27

Você também pode gostar