Common Lisp Quick Reference - Cheat SheetOct 12, 2011  · mod remFu ˙ n d) ⊲ Same as floorFu or...

28
Common Lisp Quick Reference ( Fu sinh a ) ( Fu cosh a ) ( Fu tanh a ) sinh a, cosh a, or tanh a, respectively. ( Fu asinh a ) ( Fu acosh a ) ( Fu atanh a ) asinh a, acosh a, or atanh a, respectively. ( Fu cis a ) Return e i a = cos a + i sin a. ( Fu conjugate a ) Return complex conjugate of a . ( Fu max num + ) ( Fu min num + ) Greatest or least, respectively, of nums. ( { Fu round Fu fround} { Fu floor Fu ffloor} { Fu ceiling Fu fceiling} { Fu truncate Fu ftruncate} n [d 1 ]) Return as integer or float, respectively, n/d rounded, or rounded towards −∞,+, or 0, respectively; and 2 re main- der. ( Fu mod Fu rem nd ) Same as Fu floor or Fu truncate, respectively, but return re main- der only. ( Fu random limit [state var random-state ]) Return non-negative random number less than limit , and of the same type. ( Fu make-random-state {state NIL T} NIL ) Copy of random-state object state or of the current random state; or a randomly initialized fresh random state. var random-state Current random state. ( Fu float-sign num-a [num-b 1 ]) num-b with num-a ’s sign. ( Fu signum n ) Number of magnitude 1 representing sign or phase of n . ( Fu numerator rational ) ( Fu denominator rational ) Numerator or denominator, respectively, of rational ’s canonical form. ( Fu realpart number ) ( Fu imagpart number ) Real part or imaginary part, respectively, of number . ( Fu complex real [imag 0 ]) Make a complex number. ( Fu phase number ) Angle of number ’s polar representation. ( Fu abs n ) Return |n|. ( Fu rational real ) ( Fu rationalize real ) Convert real to rational. Assume complete/limited accu- racy for real . ( Fu float real [prototype 0.0F0 ]) Convert real into float with type of prototype . 4 Quick Reference cl Common lisp Bert Burgemeister

Transcript of Common Lisp Quick Reference - Cheat SheetOct 12, 2011  · mod remFu ˙ n d) ⊲ Same as floorFu or...

  • Common Lisp Quick Reference

    (Fusinh a)(

    Fucosh a)(

    Futanh a)

    ⊲ sinh a, cosh a, or tanh a, respectively.

    (Fuasinh a)(

    Fuacosh a)(

    Fuatanh a)

    ⊲ asinh a, acosh a, or atanh a, respectively.

    (Fucis a) ⊲ Return ei a = cos a + i sina.

    (Fuconjugate a) ⊲ Return complex conjugate of a.

    (Fumax num+)(

    Fumin num+)

    ⊲ Greatest or least, respectively, of nums.

    (

    { Furound Fufround}{ Fufloor Fuffloor}{ Fuceiling Fufceiling}{ Futruncate Fuftruncate}

    n [d 1 ])

    ⊲ Return as integer or float, respectively, n/d rounded, orrounded towards −∞, +∞, or 0, respectively; and

    2remain-

    der.

    (

    { FumodFurem

    }n d)

    ⊲ Same asFufloor or

    Futruncate, respectively, but return remain-

    der only.

    (Furandom limit [state var*random-state* ])

    ⊲ Return non-negative random number less than limit , andof the same type.

    (Fumake-random-state

    [{state NIL T}NIL

    ])

    ⊲ Copy of random-state object state or of the current randomstate; or a randomly initialized fresh random state.

    var*random-state* ⊲ Current random state.(

    Fufloat-sign num-a [num-b 1 ]) ⊲ num-b with num-a’s sign.

    (Fusignum n)

    ⊲ Number of magnitude 1 representing sign or phase of n .

    (Funumerator rational)(

    Fudenominator rational)

    ⊲ Numerator or denominator, respectively, of rational ’scanonical form.

    (Furealpart number)(

    Fuimagpart number)

    ⊲ Real part or imaginary part, respectively, of number .

    (Fucomplex real [imag 0 ]) ⊲ Make a complex number.

    (Fuphase number) ⊲ Angle of number ’s polar representation.

    (Fuabs n) ⊲ Return |n|.

    (Furational real)(

    Furationalize real)

    ⊲ Convert real to rational. Assume complete/limited accu-racy for real .

    (Fufloat real [prototype 0.0F0 ])

    ⊲ Convert real into float with type of prototype .

    4

    Quick Reference

    clCommon

    lispBert Burgemeister

  • Common Lisp Quick Reference

    Contents

    1 Numbers 3

    1.1 Predicates . . . . 31.2 Numeric Functns . 31.3 Logic Functions . 51.4 Integer Functions . 61.5 Implementation-

    Dependent . . . . 6

    2 Characters 7

    3 Strings 8

    4 Conses 8

    4.1 Predicates . . . . 84.2 Lists . . . . . . 94.3 Association Lists . 104.4 Trees . . . . . . 104.5 Sets . . . . . . 11

    5 Arrays 11

    5.1 Predicates . . . . 115.2 Array Functions . 115.3 Vector Functions . 12

    6 Sequences 12

    6.1 Seq. Predicates . . 126.2 Seq. Functions . . 13

    7 Hash Tables 15

    8 Structures 16

    9 Control Structure 16

    9.1 Predicates . . . . 169.2 Variables . . . . 179.3 Functions . . . . 189.4 Macros . . . . . 19

    9.5 Control Flow . . . 209.6 Iteration . . . . 229.7 Loop Facility . . . 22

    10 CLOS 25

    10.1 Classes . . . . . 2510.2 Generic Functns . 2610.3 Method Combi-

    nation Types . . . 27

    11 Conditions and Errors 28

    12 Types and Classes 31

    13 Input/Output 33

    13.1 Predicates . . . . 3313.2 Reader . . . . . 3313.3 Character Syntax . 3413.4 Printer . . . . . 3513.5 Format . . . . . 3813.6 Streams . . . . . 4013.7 Paths and Files . . 42

    14 Packages and Symbols 43

    14.1 Predicates . . . . 4314.2 Packages . . . . 4314.3 Symbols . . . . . 4514.4 Std Packages . . 45

    15 Compiler 45

    15.1 Predicates . . . . 4515.2 Compilation . . . 4615.3 REPL & Debug . 4715.4 Declarations . . . 48

    16 External Environment 48

    Typographic Conventionsname;

    Funame;

    Mname;

    sOname;

    gFname;

    var*name*; coname⊲ Symbol defined in Common Lisp; esp. function, macro, spe-cial 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.

    {foo bar baz};

    foo

    bar

    baz

    ⊲ Either foo, or bar , or baz .

    ∣∣∣∣∣∣

    foo

    bar

    baz

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

    f̂oo ⊲ Argument foo is not evaluated.

    b̃ar ⊲ Argument bar is possibly modified.

    fooP∗ ⊲ foo∗ is evaluated as in

    sOprogn; see p. 21.

    foo;2bar ;

    n

    baz ⊲ Primary, secondary, and nth return value.

    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 numbers, or none, respectively, are equal in value.

    (Fu> number+)(

    Fu>= number+)(Fu< number+)(

    Fu 0, respectively.

    (Fuevenp integer)(

    Fuoddp integer)

    ⊲ T if integer is even or odd, respectively.

    (Funumberp foo)(

    Furealp foo)(

    Furationalp foo)(

    Fufloatp foo)(

    Fuintegerp foo)(

    Fucomplexp foo)(

    Furandom-state-p foo)

    ⊲ T if foo is of indicated type.

    1.2 Numeric Functions

    (Fu+ a 0

    ∗)(Fu* a 1 ∗) ⊲ Return ∑ a or ∏ a, respectively.(Fu– a b∗)(Fu/ a b∗)

    ⊲ Return a−∑

    b or a/∏

    b, respectively. Without any bs,return −a or 1/a, respectively.

    (Fu1+ a)(Fu1– a)

    ⊲ Return a+ 1 or a− 1, respectively.

    (

    {MincfMdecf

    }p̃lace [delta 1 ])

    ⊲ Increment or decrement the value of place by delta. Returnnew value.

    (Fuexp p)(

    Fuexpt b p)

    ⊲ Return ep or bp, respectively.

    (Fulog a [b]) ⊲ Return logb a or, without b, ln a.

    (Fusqrt n)(

    Fuisqrt n)

    ⊲√n in complex or natural numbers, respectively.

    (Fulcm integer∗ 1 )(

    Fugcd integer∗)

    ⊲ Least common multiple or greatest common denominator,respectively, of integers. (gcd) returns 0.

    copi ⊲ long-float approximation of π, Ludolph’s number.

    (Fusin a)(

    Fucos a)(

    Futan a)

    ⊲ sin a, cos a, or tan a, respectively. (a in radians.)

    (Fuasin a)(

    Fuacos a)

    ⊲ arcsin a or arccos a, respectively, in radians.

    (Fuatan a [b 1 ]) ⊲ arctan

    abin radians.

    3

  • Common Lisp Quick Reference

    3 Strings

    Strings can as well be manipulated by array and sequence functions;see pages 11 and 12.

    (Fustringp foo)(

    Fusimple-string-p foo)

    ⊲ T if foo is of indicated type.

    (

    { Fustring=Fustring-equal

    }foo bar

    ∣∣∣∣∣∣∣∣

    :start1 start-foo 0:start2 start-bar 0:end1 end-foo NIL:end2 end-bar NIL

    )

    ⊲ Return T if subsequences of foo and bar are equal.Obey/ignore, respectively, case.

    (

    Fustring{/= -not-equal}Fustring{> -greaterp}Fustring{>= -not-lessp}Fustring{< -lessp}Fustring{

  • Common Lisp Quick Reference

    1.4 Integer Functions

    (Fuinteger-length integer)

    ⊲ Number of bits necessary to represent integer .

    (Fuldb-test byte-spec integer)

    ⊲ Return T if any bit specified by byte-spec in integer is set.

    (Fuash integer count)

    ⊲ Return copy of integer arithmetically shifted left by countadding zeros at the right, or, for count < 0, shifted rightdiscarding bits.

    (Fuldb byte-spec integer)

    ⊲ Extract byte denoted by byte-spec from integer . setfable.

    (

    { Fudeposit-fieldFudpb

    }int-a byte-spec int-b)

    ⊲ Return int-b with bits denoted by byte-spec replaced bycorresponding bits of int-a, or by the low (

    Fubyte-size byte-spec)

    bits of int-a, respectively.

    (Fumask-field byte-spec integer)

    ⊲ Return copy of integer with all bits unset but those denotedby byte-spec. setfable.

    (Fubyte size position)

    ⊲ Byte specifier for a byte of size bits starting at a weight of2position .

    (Fubyte-size byte-spec)(

    Fubyte-position byte-spec)

    ⊲ Size or position, respectively, of byte-spec.

    1.5 Implementation-Dependentcoshort-floatcosingle-floatcodouble-floatcolong-float

    -

    {epsilonnegative-epsilon

    ⊲ Smallest possible number making a difference when addedor subtracted, respectively.

    coleast-negativecoleast-negative-normalizedcoleast-positivecoleast-positive-normalized

    -

    short-floatsingle-floatdouble-floatlong-float

    ⊲ Available numbers closest to −0 or +0, respectively.

    comost-negativecomost-positive

    }-

    short-floatsingle-floatdouble-floatlong-floatfixnum

    ⊲ Available numbers closest to −∞ or +∞, respectively.

    (Fudecode-float n)(

    Fuinteger-decode-float n)

    ⊲ Return significand,2exponent, and

    3sign of float n.

    (Fuscale-float n [i ]) ⊲ With n’s radix b, return nbi.

    (Fufloat-radix n)(

    Fufloat-digits n)(

    Fufloat-precision n)

    ⊲ Radix, number of digits in that radix, or precision in thatradix, respectively, of float n.

    (Fuupgraded-complex-part-type foo [environment NIL ])

    ⊲ Type of most specialized complex number able to hold partsof type foo.

    6

    Common Lisp Quick Reference

    2 Characters

    The standard-char type comprises a-z, A-Z, 0-9, Newline, Space, and!?$"’‘.:,;*+-/|\~ ^#%@&()[]{}.(

    Fucharacterp foo)(

    Fustandard-char-p char)

    ⊲ T if argument is of indicated type.

    (Fugraphic-char-p character)(

    Fualpha-char-p character )(

    Fualphanumericp character)

    ⊲ T if character is visible, alphabetic, or alphanumeric, re-spectively.

    (Fuupper-case-p character)(

    Fulower-case-p character)(

    Fuboth-case-p character)

    ⊲ Return T if character is uppercase, lowercase, or able to bein another case, respectively.

    (Fudigit-char-p character [radix 10 ])

    ⊲ Return its weight if character is a digit, or NIL otherwise.

    (Fuchar= character+)(

    Fuchar/= character+)

    ⊲ Return T if all characters, or none, respectively, are equal.

    (Fuchar-equal character+)(

    Fuchar-not-equal character+)

    ⊲ Return T if all characters, or none, respectively, are equalignoring case.

    (Fuchar> character+)(

    Fuchar>= character+)(

    Fuchar< character+)(

    Fuchar

  • Common Lisp Quick Reference

    (Fubit bit-array [subscripts ])(

    Fusbit simple-bit-array [subscripts ])

    ⊲ Return element of bit-array or of simple-bit-array . setf-able.

    (Fubit-not ˜bit-array [ ˜result-bit-array NIL ])

    ⊲ Return result of bitwise negation of bit-array. Ifresult-bit-array is T, put result in bit-array ; if it is NIL, makea new array for result.

    (

    Fubit-eqvFubit-andFubit-andc1Fubit-andc2Fubit-nandFubit-iorFubit-orc1Fubit-orc2Fubit-xorFubit-nor

    ˜bit-array-a bit-array-b [ ˜result-bit-array NIL ])

    ⊲ Return result of bitwise logical operations (cf. operations ofFuboole, p. 5) on bit-array-a and bit-array-b. If result-bit-arrayis T, put result in bit-array-a; if it is NIL, make a new arrayfor result.

    coarray-rank-limit ⊲ Upper bound of array rank; ≥ 8.coarray-dimension-limit

    ⊲ Upper bound of an array dimension; ≥ 1024.coarray-total-size-limit ⊲ Upper bound of array size; ≥ 1024.

    5.3 Vector Functions

    Vectors can as well be manipulated by sequence functions; see sec-tion 6.

    (Fuvector foo∗) ⊲ Return fresh simple vector of foo s.

    (Fusvref vector i) ⊲ Return element i of simple vector . setfable.

    (Fuvector-push foo ṽector)

    ⊲ Return NIL if vector ’s fill pointer equals size of vector . Oth-erwise replace element of vector pointed to by fill pointer withfoo; then increment fill pointer.

    (Fuvector-push-extend foo ṽector [num ])

    ⊲ Replace element of vector pointed to by fill pointer withfoo, then increment fill pointer. Extend vector ’s size by ≥num if necessary.

    (Fuvector-pop ṽector)

    ⊲ Return element of vector its fillpointer points to after decre-mentation.

    (Fufill-pointer vector) ⊲ Fill pointer of vector . setfable.

    6 Sequences

    6.1 Sequence Predicates

    (

    { FueveryFunotevery

    }test sequence+)

    ⊲ Return NIL or T, respectively, as soon as test on any set ofcorresponding elements of sequences returns NIL.

    (

    { FusomeFunotany

    }test sequence+)

    ⊲ Return value of test or NIL, respectively, as soon as test onany set of corresponding elements of sequences returns non-NIL.

    12

    Common Lisp Quick Reference

    (Fuatom foo) ⊲ Return T if foo is not a cons.

    (Futailp foo list) ⊲ Return T if foo is a tail of list .

    (Fumember foo list

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Return tail of list starting with its first element matchingfoo. Return NIL if there is no such element.

    (

    { Fumember-ifFumember-if-not

    }test list [:key function ])

    ⊲ Return tail of list starting with its first element satisfyingtest . Return NIL if there is no such element.

    (Fusubsetp list-a list-b

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Return T if list-a is a subset of list-b.

    4.2 Lists

    (Fucons foo bar) ⊲ Return new cons (foo . bar ).

    (Fulist foo∗) ⊲ Return list of foos.

    (Fulist* foo+)

    ⊲ Return list of foos with last foo becoming cdr of last cons.Return foo if only one foo given.

    (Fumake-list num [:initial-element foo NIL ])

    ⊲ New list with num elements set to foo.

    (Fulist-length list) ⊲ Length of list ; NIL for circular list .

    (Fucar list) ⊲ Car of list or NIL if list is NIL. setfable.

    (Fucdr list)(

    Furest list)

    ⊲ Cdr of list or NIL if list is NIL. setfable.

    (Funthcdr n list) ⊲ Return tail of list after calling

    Fucdr n times.

    ({ Fufirst Fusecond Futhird Fufourth Fufifth Fusixth . . . Funinth Futenth} list)⊲ Return nth element of list if any, or NIL otherwise. setfable.

    (Funth n list) ⊲ Zero-indexed nth element of list . setfable.

    (FucX r list)

    ⊲ With X being one to four as and ds representingFucars and

    Fucdrs, e.g. (

    Fucadr bar) is equivalent to (

    Fucar (

    Fucdr bar)). setfable.

    (Fulast list [num 1 ]) ⊲ Return list of last num conses of list .

    (

    { Fubutlast listFunbutlast l̃ist

    }[num 1 ]) ⊲ list excluding last num conses.

    (

    { FurplacaFurplacd

    }c̃ons object)

    ⊲ Replace car, or cdr, respectively, of cons with object .

    (Fuldiff list foo)

    ⊲ If foo is a tail of list , return preceding part of list . Other-wise return list .

    (Fuadjoin foo list

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Return list if foo is already member of list . If not, return(

    Fucons foo list ).

    (Mpop p̃lace) ⊲ Set place to (

    Fucdr place), return (

    Fucar place ).

    (Mpush foo p̃lace) ⊲ Set place to (

    Fucons foo place ).

    9

  • Common Lisp Quick Reference

    (Mpushnew foo p̃lace

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Set place to (Fuadjoin foo place ).

    (Fuappend [proper-list∗ foo NIL ])

    (Funconc [ ˜non-circular-list∗ foo NIL ])

    ⊲ Return concatenated list or, with only one argument, foo.foo can be of any type.

    (Furevappend list foo)

    (Funreconc l̃ist foo)

    ⊲ Return concatenated list after reversing order in list .

    (

    { FumapcarFumaplist

    }function list+)

    ⊲ Return list of return values of function successively invokedwith corresponding arguments, either cars or cdrs, respec-tively, from each list .

    (

    { FumapcanFumapcon

    }function list+)

    ⊲ Return list of concatenated return values of function suc-cessively invoked with corresponding arguments, either carsor cdrs, respectively, from each list . function should return alist.

    (

    { FumapcFumapl

    }function list+)

    ⊲ Return first list after successively applying function to cor-responding arguments, either cars or cdrs, respectively, fromeach list . function should have some side effects.

    (Fucopy-list list) ⊲ Return copy of list with shared elements.

    4.3 Association Lists

    (Fupairlis keys values [alist NIL ])

    ⊲ Prepend to alist an association list made from lists keysand values .

    (Fuacons key value alist)

    ⊲ Return alist with a (key . value) pair added.

    (

    { FuassocFurassoc

    }foo alist

    ∣∣∣∣∣∣

    {:test test#’eql:test-not test

    :key function

    )

    (

    { Fuassoc-if[-not]Furassoc-if[-not]

    }test alist [:key function])

    ⊲ First cons whose car, or cdr, respectively, satisfies test.

    (Fucopy-alist alist) ⊲ Return copy of alist .

    4.4 Trees

    (Futree-equal foo bar

    {:test test#’eql:test-not test

    })

    ⊲ Return T if trees foo and bar have same shape and leavessatisfying test.

    (

    { Fusubst new old treeFunsubst new old t̃ree

    }

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Make copy of tree with each subtree or leaf matching oldreplaced by new .

    (

    { Fusubst-if[-not] new test treeFunsubst-if[-not] new test t̃ree

    }[:key function])

    ⊲ Make copy of tree with each subtree or leaf satisfying testreplaced by new .

    10

    Common Lisp Quick Reference

    (

    { Fusublis association-list treeFunsublis association-list t̃ree

    }

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Make copy of tree with each subtree or leaf matching a keyin association-list replaced by that key’s value.

    (Fucopy-tree tree) ⊲ Copy of tree with same shape and leaves.

    4.5 Sets

    (

    FuintersectionFuset-differenceFuunionFuset-exclusive-or

    a b

    FunintersectionFunset-difference

    }ã b

    FununionFunset-exclusive-or

    }ã b̃

    ∣∣∣∣∣∣

    {:test function#’eql:test-not function

    :key function

    )

    ⊲ Return a ∩ b, a \ b, a ∪ b, or a△ b, respectively, of lists aand b.

    5 Arrays

    5.1 Predicates

    (Fuarrayp foo)(

    Fuvectorp foo)(

    Fusimple-vector-p foo)(

    Fubit-vector-p foo)(

    Fusimple-bit-vector-p foo)

    ⊲ T if foo is of indicated type.

    (Fuadjustable-array-p array)(

    Fuarray-has-fill-pointer-p array)

    ⊲ T if array is adjustable/has a fill pointer, respectively.

    (Fuarray-in-bounds-p array [subscripts ])

    ⊲ Return T if subscripts are in array ’s bounds.

    5.2 Array Functions

    (

    { Fumake-array dimension-sizes

    [:adjustable bool NIL

    ]Fuadjust-array ãrray dimension-sizes

    }

    ∣∣∣∣∣∣∣∣∣∣

    :element-type type T:fill-pointer {num bool}NIL:initial-element obj:initial-contents sequence:displaced-to array NIL [:displaced-index-offset i 0 ]

    )

    ⊲ Return fresh, or readjust, respectively, vector or array.

    (Fuaref array

    [subscripts

    ])

    ⊲ Return array element pointed to by subscripts. setfable.

    (Furow-major-aref array i)

    ⊲ Return ith element of array in row-major order. setfable.

    (Fuarray-row-major-index array [subscripts ])

    ⊲ Index in row-major order of the element denoted bysubscripts .

    (Fuarray-dimensions array)

    ⊲ List containing the lengths of array ’s dimensions.

    (Fuarray-dimension array i)

    ⊲ Length of ith dimension of array .

    (Fuarray-total-size array) ⊲ Number of elements in array .

    (Fuarray-rank array) ⊲ Number of dimensions of array .

    (Fuarray-displacement array) ⊲ Target array and

    2offset.

    11

  • Common Lisp Quick Reference

    8 Structures

    (Mdefstruct

    foo

    (foo

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    {:conc-name

    (:conc-name [ ̂slot-prefix foo- ]){:constructor

    (:constructor[m̂aker MAKE-foo [(ôrd-λ

    ∗)]])

    }∗

    {:copier

    (:copier [ĉopier COPY-foo ])

    (:include ŝtruct

    ŝlot

    (ŝlot [init

    {∣∣∣∣∣:type ŝl-type

    :read-only b̂

    }])

    )

    (:type

    listvector

    (vector t̂ype)

    )

    {∣∣∣∣:named(:initial-offset n̂)

    {(:print-object [ ̂o-printer ])

    (:print-function [ ̂f-printer ]){:predicate(:predicate [p̂-name foo-P ])

    )

    [d̂oc]

    slot

    (slot [init

    {∣∣∣∣∣:type ̂slot-type

    :read-only b̂ool

    }])

    )

    ⊲ Define structure foo together with functions MAKE-foo,COPY-foo and foo-P; and setfable accessors foo-slot . In-stances are of class foo or, if defstruct option :type is given,of the specified type. They can be created by (MAKE-foo{:slot value}∗) or, if ord-λ (see p. 18) is given, by (makerarg∗ {:key value}∗). In the latter case, args and :keyscorrespond to the positional and keyword parameters de-fined in ord-λ whose vars in turn correspond to slots.:print-object/:print-function generate a

    gFprint-object method

    for an instance bar of foo calling (o-printer bar stream) or(f-printer bar stream print-level), respectively. If :type with-out :named is given, no foo-P is created.

    (Fucopy-structure structure)

    ⊲ Return copy of structure with shared slot values.

    9 Control Structure

    9.1 Predicates

    (Fueq foo bar) ⊲ T if foo and bar are identical.

    (Fueql foo bar)

    ⊲ T if foo and bar are identical, or the same character, ornumbers of the same type and value.

    (Fuequal foo bar)

    ⊲ T if foo and bar areFueql, or are equivalent pathnames, or are

    conses withFuequal cars and cdrs, or are strings or bit-vectors

    withFueql elements below their fill pointers.

    (Fuequalp foo bar)

    ⊲ T if foo and bar are identical; or are the same characterignoring case; or are numbers of the same value ignoring type;or are equivalent pathnames; or are conses or arrays of thesame shape with

    Fuequalp elements; or are structures of the

    same type withFuequalp elements; or are hash-tables of the

    same size with the same :test function, the same keys in termsof :test function, and

    Fuequalp elements.

    (Funot foo) ⊲ T if foo is NIL; NIL otherwise.

    (Fuboundp symbol) ⊲ T if symbol is a special variable.

    16

    Common Lisp Quick Reference

    (Fumismatch sequence-a sequence-b

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start1 start-a 0:start2 start-b 0:end1 end-a NIL:end2 end-b NIL:key function

    )

    ⊲ Return position in sequence-a where sequence-a andsequence-b begin to mismatch. Return NIL if they matchentirely.

    6.2 Sequence Functions

    (Fumake-sequence sequence-type size [:initial-element foo])

    ⊲ Make sequence of sequence-type with size elements.

    (Fuconcatenate type sequence∗)

    ⊲ Return concatenated sequence of type.

    (Fumerge type ˜sequence-a ˜sequence-b test [:key function NIL ])

    ⊲ Return interleaved sequence of type. Merged sequence willbe sorted if both sequence-a and sequence-b are sorted.

    (Fufill ˜sequence foo

    {∣∣∣∣:start start 0:end end NIL

    })

    ⊲ Return sequence after setting elements between start andend to foo.

    (Fulength sequence)

    ⊲ Return length of sequence (being value of fill pointer ifapplicable).

    (Fucount foo sequence

    ∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start start 0:end end NIL:key function

    )

    ⊲ Return number of elements in sequence which match foo.

    (

    { Fucount-ifFucount-if-not

    }test sequence

    ∣∣∣∣∣∣∣∣

    :from-end bool NIL:start start 0:end end NIL:key function

    )

    ⊲ Return number of elements in sequence which satisfy test.

    (Fuelt sequence index)

    ⊲ Return element of sequence pointed to by zero-indexedindex . setfable.

    (Fusubseq sequence start [end NIL ])

    ⊲ Return subsequence of sequence between start and end.setfable.

    (

    { FusortFustable-sort

    }˜sequence test [:key function ])

    ⊲ Return sequence sorted. Order of elements consideredequal is not guaranteed/retained, respectively.

    (Fureverse sequence)

    (Funreverse ˜sequence)

    ⊲ Return sequence in reverse order.

    (

    { FufindFuposition

    }foo sequence

    ∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not test

    :start start 0:end end NIL:key function

    )

    ⊲ Return first element in sequence which matches foo, or itsposition relative to the begin of sequence, respectively.

    13

  • Common Lisp Quick Reference

    (

    Fufind-ifFufind-if-notFuposition-ifFuposition-if-not

    test sequence

    ∣∣∣∣∣∣∣∣

    :from-end bool NIL:start start 0:end end NIL:key function

    )

    ⊲ Return first element in sequence which satisfies test, or itsposition relative to the begin of sequence , respectively.

    (Fusearch sequence-a sequence-b

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start1 start-a 0:start2 start-b 0:end1 end-a NIL:end2 end-b NIL:key function

    )

    ⊲ Search sequence-b for a subsequence matching sequence-a.Return position in sequence-b, or NIL.

    (

    { Furemove foo sequenceFudelete foo ˜sequence

    }

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start start 0:end end NIL:key function:count count NIL

    )

    ⊲ Make copy of sequence without elements matching foo.

    (

    Furemove-ifFuremove-if-not

    }test sequence

    Fudelete-ifFudelete-if-not

    }test ˜sequence

    ∣∣∣∣∣∣∣∣∣

    :from-end bool NIL:start start 0:end end NIL:key function:count count NIL

    )

    ⊲ Make copy of sequence with all (or count) elements satis-fying test removed.

    (

    { Furemove-duplicates sequenceFudelete-duplicates ˜sequence

    }

    ∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start start 0:end end NIL:key function

    )

    ⊲ Make copy of sequence without duplicates.

    (

    { Fusubstitute new old sequenceFunsubstitute new old ˜sequence

    }

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :from-end bool NIL{:test function#’eql:test-not function

    :start start 0:end end NIL:key function:count count NIL

    )

    ⊲ Make copy of sequence with all (or count) olds replaced bynew .

    (

    Fusubstitute-ifFusubstitute-if-not

    }new test sequence

    Funsubstitute-ifFunsubstitute-if-not

    }new test ˜sequence

    ∣∣∣∣∣∣∣∣∣

    :from-end bool NIL:start start 0:end end NIL:key function:count count NIL

    )

    ⊲ Make copy of sequence with all (or count) elements satis-fying test replaced by new .

    (Fureplace ˜sequence-a sequence-b

    ∣∣∣∣∣∣∣∣

    :start1 start-a 0:start2 start-b 0:end1 end-a NIL:end2 end-b NIL

    )

    ⊲ Replace elements of sequence-a with elements ofsequence-b.

    (Fumap type function sequence+)

    ⊲ Apply function successively to corresponding elements ofthe sequences. Return values as a sequence of type. If type isNIL, return NIL.

    14

    Common Lisp Quick Reference

    (Fumap-into ˜result-sequence function sequence∗)

    ⊲ Store into result-sequence successively values of functionapplied to corresponding elements of the sequences.

    (Fureduce function sequence

    ∣∣∣∣∣∣∣∣∣

    :initial-value foo NIL:from-end bool NIL:start start 0:end end NIL:key function

    )

    ⊲ Starting with the first two elements of sequence, applyfunction successively to its last return value together withthe next element of sequence . Return last value of function.

    (Fucopy-seq sequence)

    ⊲ Copy of sequence with shared elements.

    7 Hash Tables

    Key-value storage similar to hash tables can as well be achieved usingassociation lists and property lists; see pages 10 and 17.

    (Fuhash-table-p foo) ⊲ Return T if foo is of type hash-table.

    (Fumake-hash-table

    ∣∣∣∣∣∣∣∣

    :test {Fueq Fueql Fuequal Fuequalp}#’eql:size int:rehash-size num:rehash-threshold num

    )

    ⊲ Make a hash table.

    (Fugethash key hash-table [default NIL ])

    ⊲ Return object with key if any or default otherwise; and2T

    if found,2NIL otherwise. setfable.

    (Fuhash-table-count hash-table)

    ⊲ Number of entries in hash-table .

    (Furemhash key ˜hash-table)

    ⊲ Remove from hash-table entry with key and return T if itexisted. Return NIL otherwise.

    (Fuclrhash ˜hash-table) ⊲ Empty hash-table .

    (Fumaphash function hash-table)

    ⊲ Iterate over hash-table calling function on key and value.Return NIL.

    (Mwith-hash-table-iterator (foo hash-table) (declare d̂ecl∗)∗ form

    P∗)⊲ Return values of forms. In forms, invocations of (foo) re-turn: T if an entry is returned; its key; its value.

    (Fuhash-table-test hash-table)

    ⊲ Test function used in hash-table .

    (Fuhash-table-size hash-table)(

    Fuhash-table-rehash-size hash-table)(

    Fuhash-table-rehash-threshold hash-table)

    ⊲ Current size, rehash-size, or rehash-threshold, respectively,as used in

    Fumake-hash-table.

    (Fusxhash foo)

    ⊲ Hash code unique for any argumentFuequal foo.

    15

  • Common Lisp Quick Reference

    [&allow-other-keys]] [

    &environment var])

    ⊲ Specify how to setf a place accessed by function .Short form: (setf (function arg∗) value-form) is replaced 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 accessedwhere setf-λ and s-var∗ describe the arguments of functionand the value(s) to be stored, respectively; and that returnsthe value(s) of s-var∗. forms are enclosed in an implicit

    sOblock

    named function.

    (Mdefine-setf-expander function (macro-λ∗) (declare d̂ecl∗)∗ [d̂oc]

    formP∗)

    ⊲ Specify how to setf a place accessed by function . On in-vocation of (setf (function arg∗) value-form), form∗ mustexpand into code returning arg-vars , args , newval-vars ,set-form, and get-form as described with

    Fuget-setf-expansion

    where the elements of macro lambda list macro-λ∗ are boundto corresponding args. forms are enclosed in an implicit

    sOblock

    named function.

    (Fuget-setf-expansion place [environment NIL ])

    ⊲ Return lists of temporary variables arg-vars and of cor-responding

    2args as given with place , list

    3newval-vars with

    temporary variables corresponding to the new values, and

    4set-form and

    5get-form specifying in terms of arg-vars and

    newval-vars how to setf and how to read place .

    (Mdefine-modify-macro foo (

    [&optional{

    var

    (var[init NIL [supplied-p]

    ])

    }∗][&rest var ]) function [d̂oc])

    ⊲ Define macro foo able to modify a place. On invocation of(foo place arg∗), the value of function applied to place andargs will be stored into place and returned.

    colambda-list-keywords

    ⊲ List of macro lambda list keywords. These are at least:

    &whole var⊲ Bind var to the entire macro call form.

    &optional var∗

    ⊲ Bind vars to corresponding arguments if any.

    {&rest &body} var⊲ Bind var to a list of remaining arguments.

    &key var∗

    ⊲ Bind vars to corresponding keyword arguments.

    &allow-other-keys⊲ Suppress keyword argument checking. Callers can doso using :allow-other-keys T.

    &environment var⊲ Bind var to the lexical compilation environment.

    &aux var∗ ⊲ Bind vars as insOlet*.

    9.5 Control Flow

    (sOif test then [else NIL ])

    ⊲ Return values of then if test returns T; return values of elseotherwise.

    (Mcond (test then

    P∗test )

    ∗)⊲ Return the values of the first then∗ whose test returns T;return NIL if all tests return NIL.

    (

    {MwhenMunless

    }test foo

    P∗)

    ⊲ Evaluate foos and return their values if test returns T orNIL, respectively. Return NIL otherwise.

    20

    Common Lisp Quick Reference

    (Fuconstantp foo [environment NIL ])

    ⊲ T if foo is a constant form.

    (Fufunctionp foo) ⊲ T if foo is of type function.

    (Fufboundp

    {foo

    (setf foo)

    }) ⊲ T if foo is a global function or macro.

    9.2 Variables

    (

    {MdefconstantMdefparameter

    }f̂oo form [d̂oc])

    ⊲ Assign value of form to global constant/dynamic variablefoo.

    (Mdefvar f̂oo

    [form [d̂oc]

    ])

    ⊲ Unless bound already, assign value of form to dynamic vari-able foo.

    (

    {MsetfMpsetf

    }{place form}∗)

    ⊲ Set places to primary values of forms. Return values oflast form/NIL; work sequentially/in parallel, respectively.

    (

    { sOsetqMpsetq

    }{symbol form}∗)

    ⊲ Set symbols to primary values of forms. Return value oflast form/NIL; work sequentially/in parallel, respectively.

    (Fuset s̃ymbol foo) ⊲ Set symbol ’s value cell to foo. Deprecated.

    (Mmultiple-value-setq vars form)

    ⊲ Set elements of vars to the values of form. Return form ’sprimary value.

    (Mshiftf p̃lace+ foo)

    ⊲ Store value of foo in rightmost place shifting values ofplaces left, returning first place .

    (Mrotatef p̃lace∗)

    ⊲ Rotate values of places left, old first becoming new lastplace ’s value. Return NIL.

    (Fumakunbound f̃oo) ⊲ Delete special variable foo if any.

    (Fuget symbol key

    [default NIL

    ])

    (Fugetf place key

    [default NIL

    ])

    ⊲ First entry key from property list stored in symbol/in place ,respectively, or default if there is no key. setfable.

    (Fuget-properties property-list keys)

    ⊲ Return key and2value of first entry from property-list

    matching a key from keys, and3tail of property-list starting

    with that key. Return NIL,2NIL, and

    3NIL if there was no

    matching key in property-list .

    (Furemprop s̃ymbol key)

    (Mremf p̃lace key)

    ⊲ Remove first entry key from property list stored insymbol/in place , respectively. Return T if key was there, orNIL otherwise.

    17

  • Common Lisp Quick Reference

    9.3 Functions

    Below, ordinary lambda list (ord-λ∗) has the form

    (var∗[&optional

    {var

    (var[init NIL [supplied-p]

    ])

    }∗][&rest var ]

    [&key

    var

    (

    {var

    (:key var)

    } [init NIL [supplied-p]

    ])

    [&allow-other-keys]]

    [&aux

    {var

    (var [init NIL ])

    }∗]).

    supplied-p is T if there is a corresponding argument. init forms canrefer to any init and supplied-p to their left.

    (

    Mdefun

    {foo (ord-λ∗)(setf foo) (new-value ord-λ∗)

    Mlambda (ord-λ∗)

    (declare d̂ecl

    ∗)∗ [d̂oc]

    formP∗)

    ⊲ Define a function named foo or (setf foo), or an anonymousfunction, respectively, which applies forms to ord-λs. ForMdefun, forms are enclosed in an implicit

    sOblock named foo.

    (

    {sOfletsOlabels

    }((

    {foo (ord-λ∗)(setf foo) (new-value ord-λ∗)

    }(declare ̂local-decl∗)∗

    [d̂oc] local-formP∗)∗) (declare d̂ecl∗)∗ form

    P∗)⊲ Evaluate forms with locally defined functions foo. Globallydefined functions of the same name are shadowed. Each foois also the name of an implicit

    sOblock around its corresponding

    local-form∗. Only forsOlabels, functions foo are visible inside

    local-forms . Return values of forms.

    (sOfunction

    {foo

    (Mlambda form∗)

    })

    ⊲ Return lexically innermost function named foo or a lexicalclosure of the

    Mlambda expression.

    (Fuapply

    {function

    (setf function)

    }arg∗ args)

    ⊲ Values of function called with args and the list elements ofargs . setfable if function is one of

    Fuaref,

    Fubit, and

    Fusbit.

    (Fufuncall function arg∗) ⊲ Values of function called with args.

    (sOmultiple-value-call function form∗)

    ⊲ Call function with all the values of each form as its argu-ments. Return values returned by function .

    (Fuvalues-list list) ⊲ Return elements of list .

    (Fuvalues foo∗)

    ⊲ Return as multiple values the primary values of the foos.setfable.

    (Fumultiple-value-list form) ⊲ List of the values of form .

    (Mnth-value n form)

    ⊲ Zero-indexed nth return value of form.

    (Fucomplement function)

    ⊲ Return new function with same arguments and same sideeffects as function, but with complementary truth value.

    (Fuconstantly foo)

    ⊲ Function of any number of arguments returning foo.

    (Fuidentity foo) ⊲ Return foo.

    (Fufunction-lambda-expression function)

    ⊲ If available, return lambda expression of function,2NIL if

    function was defined in an environment without bindings,and

    3name of function.

    (Fufdefinition

    {foo

    (setf foo)

    })

    ⊲ Definition of global function foo. setfable.

    18

    Common Lisp Quick Reference

    (Fufmakunbound foo)

    ⊲ Remove global function or macro definition foo.

    cocall-arguments-limitcolambda-parameters-limit

    ⊲ Upper bound of the number of function arguments orlambda list parameters, respectively; ≥ 50.

    comultiple-values-limit

    ⊲ Upper bound of the number of values a multiple value canhave; ≥ 20.

    9.4 Macros

    Below, macro lambda list (macro-λ∗) has the form of either

    ([&whole var ] [E ]

    {var

    (macro-λ∗)

    }∗[E ]

    [&optional

    var

    (

    {var

    (macro-λ∗)

    } [init NIL [supplied-p]

    ])

    ] [E ]

    [

    {&rest&body

    } {rest-var

    (macro-λ∗)

    }] [E ]

    [&key

    var

    (

    var

    (:key

    {var

    (macro-λ∗)

    })

    [init NIL [supplied-p]

    ])

    [E ]

    [&allow-other-keys]][&aux

    {var

    (var [init NIL ])

    }∗] [E ])

    or

    ([&whole var ] [E ]

    {var

    (macro-λ∗)

    }∗[E ] [&optional

    var

    (

    {var

    (macro-λ∗)

    } [init NIL [supplied-p]

    ])

    ] [E ] . rest-var).

    One toplevel [E ] may be replaced by &environment var . supplied-pis T if there is a corresponding argument. init forms can refer to anyinit and supplied-p to their left.

    (

    {MdefmacroFudefine-compiler-macro

    } {foo

    (setf foo)

    }(macro-λ∗) (declare d̂ecl∗)∗

    [d̂oc] formP∗)

    ⊲ Define macro foo which on evaluation as (foo tree) appliesexpanded forms to arguments from tree, which correspondsto tree-shaped macro-λs. forms are enclosed in an implicitsOblock named foo.

    (Mdefine-symbol-macro foo form)

    ⊲ Define symbol macro foo which on evaluation evaluates ex-panded form.

    (sOmacrolet ((foo (macro-λ∗) (declare ̂local-decl∗)∗ [d̂oc]

    macro-formP∗)∗) (declare d̂ecl∗)∗ form

    P∗)⊲ Evaluate forms with locally defined mutually invisiblemacros foo which are enclosed in implicit

    sOblocks of the same

    name.

    (sOsymbol-macrolet ((foo expansion-form)∗) (declare d̂ecl∗)∗ form

    P∗)⊲ Evaluate forms with locally defined symbol macros foo.

    (Mdefsetf ̂function

    {ûpdater [d̂oc]

    (setf-λ∗) (s-var∗) (declare d̂ecl∗)∗ [d̂oc] formP∗

    })

    where defsetf lambda list (setf-λ∗) has the form

    (var∗[&optional

    {var

    (var[init NIL [supplied-p]

    ])

    }∗]

    [&rest var ][&key

    var

    (

    {var

    (:key var)

    } [init NIL [supplied-p]

    ])

    19

  • Common Lisp Quick Reference

    by {step 1 function#’cdr}⊲ Specify the (positive) decrement or increment orthe function of one argument returning the next partof the list.

    = foo [then bar foo ]

    ⊲ Bind var initially to foo and later to bar .

    across vector⊲ Bind var to successive elements of vector .

    being {the each}⊲ Iterate over a hash table or a package.

    {hash-key hash-keys} {of in} hash-table [using(hash-value value)]⊲ Bind var successively to the keys of hash-table ;bind value to corresponding values.

    {hash-value hash-values} {of in} hash-table [using(hash-key key)]⊲ Bind var successively to the values ofhash-table ; bind key to corresponding keys.

    {symbol symbols present-symbol present-symbolsexternal-symbol external-symbols} [{of in}package var*package* ]⊲ Bind var successively to the accessible symbols,or the present symbols, or the external symbolsrespectively, of package .

    {do doing} form+⊲ Evaluate forms in every iteration.

    {if when unless} test i-clause {and j-clause}∗ [else k-clause{and l-clause}∗] [end]⊲ If test returns T, T, or NIL, respectively, evaluatei-clause and j-clauses; otherwise, evaluate k-clause andl-clauses.

    it ⊲ Inside i-clause or k-clause: value of test .

    return {form it}⊲ Return immediately, skipping any finally parts, withvalues of form or it.

    {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 ter-mination.

    {append appending nconc nconcing} {form it} [into list ]⊲ Concatenate values of form or it, which should be lists,into list by the means of

    Fuappend or

    Funconc, respectively.

    If no list is given, collect into an anonymous list which isreturned after termination.

    {count counting} {form it} [into n] [type]⊲ Count the number of times the value of form or of itis T. If no n is given, count into an anonymous variablewhich is returned after termination.

    {sum summing} {form it} [into sum ] [type]⊲ Calculate the sum of the primary values of form or ofit. If no sum is given, sum into an anonymous variablewhich is returned after termination.

    {maximize maximizing minimize minimizing} {form it} [intomax-min ] [type]⊲ Determine the maximum or minimum, respectively, ofthe primary values of form or of it. If no max-min isgiven, use an anonymous variable which is returned aftertermination.

    {initially finally} form+⊲ Evaluate forms before begin, or after end, respectively,of iterations.

    repeat num⊲ Terminate

    Mloop after num iterations; num is evaluated

    once.

    24

    Common Lisp Quick Reference

    (Mcase test (

    {(k̂ey∗)

    k̂ey

    }foo

    P∗)∗[(

    {otherwiseT

    }bar

    P∗)NIL])

    ⊲ Return the values of the first foo∗ one of whose keys is eqltest . Return values of bar s if there is no matching key.

    (

    {MecaseMccase

    }test (

    {(k̂ey∗)

    k̂ey

    }foo

    P∗)∗)

    ⊲ Return the values of the first foo∗ one of whose keys is eqltest . Signal non-correctable/correctable type-error and returnNIL if there is no matching key.

    (Mand form∗ T )

    ⊲ Evaluate forms from left to right. Immediately return NILif one form’s value is NIL. Return values of last form other-wise.

    (Mor form∗ NIL )

    ⊲ Evaluate forms from left to right. Immediately returnprimary value of first non-NIL-evaluating form, or all valuesif last form is reached. Return NIL if no form returns T.

    (sOprogn form∗ NIL )

    ⊲ Evaluate forms sequentially. Return values of last form .

    (sOmultiple-value-prog1 form-r form∗)(

    Mprog1 form-r form∗)(

    Mprog2 form-a form-r form∗)

    ⊲ Evaluate forms in order. Return values/primary value, re-spectively, of form-r .

    (

    {sOletsOlet*} ({∣∣∣∣name(name [value NIL ])}∗) (declare d̂ecl∗)∗ formP∗)

    ⊲ Evaluate forms with names lexically bound (in parallel orsequentially, respectively) to values. Return values of forms.

    (

    {MprogMprog*} ({∣∣∣∣name(name [value NIL ])}∗) (declare d̂ecl∗)∗ {t̂agform}∗)

    ⊲ EvaluatesOtagbody-like body with names lexically bound (in

    parallel or sequentially, respectively) to values. Return NILor explicitly

    Mreturned values. Implicitly, the whole form is a

    sOblock named NIL.

    (sOprogv symbols values form

    P∗)⊲ Evaluate forms with locally established dynamic bindingsof symbols to values or NIL. Return values of forms.

    (sOunwind-protect protected cleanup∗)

    ⊲ Evaluate protected and then, no matter how control leavesprotected , cleanups. Return values of protected .

    (Mdestructuring-bind destruct-λ bar (declare d̂ecl∗)∗ form

    P∗)⊲ Evaluate forms with variables from tree destruct-λ boundto corresponding elements of tree bar , and return their values.destruct-λ resembles macro-λ (section 9.4), but without any&environment clause.

    (Mmultiple-value-bind (v̂ar∗) values-form (declare d̂ecl∗)∗

    body-formP∗)

    ⊲ Evaluate body-forms with vars lexically bound to the re-turn values of values-form . Return values of body-form s.

    (sOblock name form

    P∗)⊲ Evaluate forms in a lexical environment, and return theirvalues unless interrupted by

    sOreturn-from.

    (sOreturn-from foo [result NIL ])(

    Mreturn [result NIL ])

    ⊲ Have nearest enclosingsOblock named foo/named NIL, re-

    spectively, return with values of result .

    (sOtagbody {t̂ag form}∗)

    ⊲ Evaluate forms in a lexical environment. tags (symbolsor integers) have lexical scope and dynamic extent, and aretargets for

    sOgo. Return NIL.

    21

  • Common Lisp Quick Reference

    (sOgo t̂ag)

    ⊲ Within the innermost possible enclosingsOtagbody, jump to

    a tag eql tag .

    (sOcatch tag form

    P∗)⊲ Evaluate forms and return their values unless interruptedby

    sOthrow.

    (sOthrow tag form)

    ⊲ Have the nearest dynamically enclosingsOcatch with a tag

    Fueq tag return with the values of form.

    (Fusleep n) ⊲ Wait n seconds, return NIL.

    9.6 Iteration

    (

    {MdoMdo*} ({var(var [start [step]])}∗) (stop resultP∗) (declare d̂ecl∗)∗{

    t̂ag

    form

    }∗)

    ⊲ EvaluatesOtagbody-like body with vars successively bound

    according to the values of the corresponding start and stepforms. vars are bound in parallel/sequentially, respectively.Stop iteration when stop is T. Return values of result∗. Im-plicitly, the whole form is a

    sOblock named NIL.

    (Mdotimes (var i [result NIL ]) (declare d̂ecl

    ∗)∗ {t̂ag form}∗)⊲ Evaluate

    sOtagbody-like body with var successively bound to

    integers from 0 to i − 1. Upon evaluation of result , var is i .Implicitly, the whole form is a

    sOblock named NIL.

    (Mdolist (var list [result NIL ]) (declare d̂ecl

    ∗)∗ {t̂ag form}∗)⊲ Evaluate

    sOtagbody-like body with var successively bound

    to the elements of list . Upon evaluation of result , var is NIL.Implicitly, the whole form is a

    sOblock named NIL.

    9.7 Loop Facility

    (Mloop form∗)

    ⊲ Simple Loop. If forms do not contain any atomic LoopFacility keywords, evaluate them forever in an implicit

    sOblock

    named NIL.

    (Mloop clause∗)

    ⊲ Loop Facility. For Loop Facility keywords see below andFigure 1.

    named n NIL ⊲ GiveMloop’s implicit

    sOblock a name.

    {with{var-s

    (var-s∗)

    }[d-type] [= foo]}+

    {and{var-p

    (var-p∗)

    }[d-type] [= bar ]}∗

    where destructuring type specifier d-type has the form{fixnum float T NIL

    {of-type

    {type

    (type∗)

    }}}

    ⊲ Initialize (possibly trees of) local variables var-s se-quentially and var-p in parallel.

    {{for as}

    {var-s

    (var-s∗)

    }[d-type]

    }+ {and

    {var-p

    (var-p∗)

    }[d-type]

    }∗

    ⊲ Begin of iteration control clauses. Initialize and step(possibly trees of) local variables var-s sequentially andvar-p in parallel. Destructuring type specifier d-type aswith with.

    {upfrom from downfrom} start⊲ Start stepping with start

    {upto downto to below above} form⊲ Specify form as the end value for stepping.

    {in on} list⊲ Bind var to successive elements/tails, respectively,of list .

    22

    Common Lisp Quick Reference

    (loop[namednNIL]

    with

    { var

    (var∗)}

    [d-type][=

    foo]{a

    nd

    { var

    (var∗)}

    [d-type][=

    bar]}

    for

    as

    }{ v

    ar

    (var∗)}

    [d-type]

    [{upfrom

    from

    }start

    0

    ][

    upto

    to below

    form

    ]

    from

    start

    {downto

    above

    }form

    downfrom

    start

    [ downto

    to above

    form

    ]

    [bystep1]

    in on

    }list

    [byfunction

    #’cdr]

    =foo[thenbarfoo]

    across

    vector

    being

    {the

    each

    }

    hash-key[s]

    {of

    in

    }hash

    [using(hash-valuev)]

    hash-value[s]{

    of

    in

    }hash

    [using(hash-keyk)]

    symbol[s]

    present-symbol[s]

    external-symbol[s]

    [{

    of

    in

    }package

    var *package*] F 0{

    and

    Fi

    } ∗

    T1

    do[ing]form

    +

    if when

    unless

    test

    Ci{a

    nd

    Cj}∗

    [else

    Ck{a

    nd

    Cl}∗

    ][end]

    return

    {form

    itco

    llect[ing]

    append[ing]

    nco

    nc[ing]

    {form

    it

    }[into

    list]

    count[ing]

    sum[m

    ing]

    maximize

    maximizing

    minim

    ize

    minim

    izing

    {form

    it

    }[into

    num][type]

    C0

    initially

    finally

    }form

    +

    repeatnum

    while

    until

    always

    neve

    rthereis

    test

    T2

    )

    Figure 1: Loop Facility,Overview.

    23

  • Common Lisp Quick Reference

    (Mdefine-method-combination c-type

    ∣∣∣∣∣∣

    :documentation ŝtring:identity-with-one-argument bool NIL:operator operator c-type

    )

    ⊲ Short Form. Define new method-combination c-type. Ina generic function using c-type, evaluate most specific:around method supplying the values of the generic func-tion. From within this method,

    Fucall-next-method can

    call less specific :around methods if there are any. Ifnot, or if there are no :around methods at all, re-turn from the calling call-next-method or from thegeneric function, respectively, the values of (operator(primary-method gen-arg∗)∗), gen-arg∗ being the argumentsof the generic function. The primary-methods are ordered[{:most-specific-first

    :most-specific-last

    }:most-specific-first

    ](specified as c-arg in

    Mdefgeneric). Using c-type as the qualifier in

    Mdefmethod makes

    the method primary.

    (Mdefine-method-combination c-type (ord-λ∗) ((group

    *(qualifier∗

    [*])predicate

    ∣∣∣∣∣∣∣∣

    :description control

    :order

    {:most-specific-first:most-specific-last

    }:most-specific-first

    :required bool

    )∗)

    ∣∣∣∣∣∣∣∣

    (:arguments method-combination-λ∗)(:generic-function symbol)

    (declare d̂ecl∗)∗

    d̂oc

    bodyP∗)

    ⊲ Long Form. Define new method-combination c-type. A callto a generic function using c-type will be equivalent to a callto the forms returned by body∗ with ord-λ∗ bound to c-arg∗

    (cf.Mdefgeneric), with symbol bound to the generic function,

    with method-combination-λ∗ bound to the arguments of thegeneric function, and with groups bound to lists of meth-ods. An applicable method becomes a member of the left-most group whose predicate or qualifiers match. Methodscan be called via

    Mcall-method. Lambda lists (ord-λ∗) and

    (method-combination-λ∗) according to ord-λ on p. 18, thelatter enhanced by an optional &whole argument.

    (Mcall-method

    {m̂ethod

    (Mmake-method f̂orm)

    }[(

    {̂next-method

    (Mmake-method f̂orm)

    }∗)])

    ⊲ From within an effective method form, call method withthe arguments of the generic function and with informationabout its next-methods; return its values.

    11 Conditions and Errors

    For standardized condition types cf. Figure 2 on page 32.

    (Mdefine-condition foo (parent-type∗ condition )

    (

    slot

    (slot

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    {:reader reader}∗

    {:writer{writer

    (setf writer)

    }}∗

    {:accessor accessor}∗

    :allocation

    {:instance:class

    }:instance

    {:initarg :initarg-name}∗:initform form:type type:documentation slot-doc

    )

    )

    ∣∣∣∣∣∣∣∣

    (:default-initargs {name value}∗)(:documentation condition-doc)

    (:report

    {string

    report-function

    })

    )

    28

    Common Lisp Quick Reference

    {while until} test⊲ Continue iteration until test returns NIL or T, respec-tively.

    {always never} test⊲ Terminate

    Mloop returning NIL and skipping any finally

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

    Mloop with its default return value set to T.

    thereis test⊲ Terminate

    Mloop when test is T and return value of test,

    skipping any finally parts. Otherwise continueMloop with

    its default return value set to NIL.

    (Mloop-finish)

    ⊲ TerminateMloop immediately executing any finally

    clauses and returning any accumulated results.

    10 CLOS

    10.1 Classes

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

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

    (Mdefclass foo (superclass∗ standard-object )

    (

    slot

    (slot

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    {:reader reader}∗

    {:writer{writer

    (setf writer)

    }}∗

    {:accessor accessor}∗

    :allocation

    {:instance:class

    }:instance

    {:initarg :initarg-name}∗:initform form:type type:documentation slot-doc

    )

    )

    ∣∣∣∣∣∣

    (:default-initargs {name value}∗)(:documentation class-doc)(:metaclass name standard-class )

    )

    ⊲ Define, as a subclass of superclasses, class foo . In a newinstance i , a slot ’s value defaults to form unless set via:initarg-name ; it is readable via (reader i) or (accessor i),and writeable via (writer value i) or (setf (accessor i) value).With :allocation :class, slot is shared by all instances of classfoo.

    (Fufind-class symbol

    [errorp T [environment ]

    ])

    ⊲ Return class named symbol . setfable.

    (gFmake-instance class {:initarg value}∗ other-keyarg∗)

    ⊲ Make new instance of class .

    (gFreinitialize-instance instance {:initarg value}∗ other-keyarg∗)

    ⊲ Change local slots of instance according to initargs.

    (Fuslot-value foo slot) ⊲ Return value of slot in foo . setfable.

    (Fuslot-makunbound instance slot)

    ⊲ Make slot in instance unbound.

    (

    {Mwith-slots ({ŝlot (v̂ar ŝlot)}∗)Mwith-accessors ((v̂ar ̂accessor)∗)

    }instance (declare d̂ecl∗)∗

    formP∗)

    ⊲ Return values of forms after evaluating them in a lexicalenvironment with slots of instance visible as setfable slots orvars/with accessor s of instance visible as setfable vars.

    (gFclass-name class)((setf

    gFclass-name) new-name class)

    ⊲ Get/set name of class .

    (Fuclass-of foo) ⊲ Class foo is a direct instance of.

    25

  • Common Lisp Quick Reference

    (gFchange-class ˜instance new-class {:initarg value}∗ other-keyarg∗)

    ⊲ Change class of instance to new-class .

    (gFmake-instances-obsolete class) ⊲ Update instances of class .

    (

    { gFinitialize-instance (instance)gFupdate-instance-for-different-class previous current

    }

    {:initarg value}∗ other-keyarg∗)⊲ Its primary method sets slots on behalf of

    gFmake-instance/of

    gFchange-class by means of

    gFshared-initialize.

    (gFupdate-instance-for-redefined-class instances added-slots

    discarded-slots property-list {:initarg value}∗ other-keyarg∗)⊲ Its primary method sets slots on behalf ofgFmake-instances-obsolete by means of

    gFshared-initialize.

    (gFallocate-instance class {:initarg value}∗ other-keyarg∗)

    ⊲ Return uninitialized instance of class . Called bygFmake-instance.

    (gFshared-initialize instance

    {slots

    T

    }{:initarg value}∗ other-keyarg∗)

    ⊲ Fill instance’s slots using initargs and :initform forms.

    (gFslot-missing class object slot

    setfslot-boundpslot-makunboundslot-value

    [value])

    ⊲ Called in case of attempted access to missing slot . Its pri-mary method signals error.

    (gFslot-unbound class instance slot)

    ⊲ Called byFuslot-value in case of unbound slot . Its primary

    method signals unbound-slot.

    10.2 Generic Functions

    (Funext-method-p) ⊲ T if enclosing method has a next method.

    (Mdefgeneric

    {foo

    (setf foo)

    }(required-var∗

    [&optional

    {var

    (var)

    }∗] [&rest

    var] [

    &key

    {var

    (var (:key var))

    }∗[&allow-other-keys]

    ])

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    (:argument-precedence-order required-var+)(declare (optimize arg∗)+)

    (:documentation ŝtring)(:generic-function-class class standard-generic-function )

    (:method-class class standard-method )(:method-combination c-type standard c-arg

    ∗)(:method defmethod-args)∗

    )

    ⊲ Define generic function foo. defmethod-args resemble thoseof

    Mdefmethod. For c-type see section 10.3.

    (Fuensure-generic-function

    {foo

    (setf foo)

    }

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :argument-precedence-order required-var+

    :declare (optimize arg∗)+

    :documentation string:generic-function-class class:method-class class:method-combination c-type c-arg∗

    :lambda-list lambda-list:environment environment

    )

    ⊲ Define or modify generic function foo.:generic-function-class and :lambda-list have to be com-patible with a pre-existing generic function or with existingmethods, respectively. Changes to :method-class do notpropagate to existing methods. For c-type see section 10.3.

    26

    Common Lisp Quick Reference

    (Mdefmethod

    {foo

    (setf foo)

    }[

    :before:after:aroundqualifier∗

    primary method ]

    (

    var

    (spec-var

    {class

    (eql bar)

    })

    ∗[&optional

    {var

    (var[init [supplied-p]

    ])

    }∗][&rest var ]

    [&key

    var

    (

    {var

    (:key var)

    }[init [supplied-p]

    ])

    [&allow-other-keys]]

    [&aux

    {var

    (var [init ])

    }∗])

    {∣∣∣∣∣(declare d̂ecl∗)∗

    d̂oc

    }form

    P∗)

    ⊲ Define new method for generic function foo. spec-vars spe-cialize to either being of class or being eql bar , respectively.On invocation, vars and spec-vars of the new method act likeparameters of a function with body form∗. forms are en-closed in an implicit

    sOblock foo. Applicable qualifiers depend

    on the method-combination type; see section 10.3.

    (

    { gFadd-methodgFremove-method

    }generic-function method)

    ⊲ Add (if necessary) or remove (if any) method to/fromgeneric-function.

    (gFfind-method generic-function qualifiers specializers [error T ])

    ⊲ Return suitable method, or signal error.

    (gFcompute-applicable-methods generic-function args)

    ⊲ List of methods suitable for args , most specific first.

    (Fucall-next-method arg∗ current args )

    ⊲ From within a method, call next method with args; returnits values.

    (gFno-applicable-method generic-function arg∗)

    ⊲ Called on invocation of generic-function on args if there isno applicable method. Default method signals error.

    (

    { Fuinvalid-method-error methodFumethod-combination-error

    }control arg∗)

    ⊲ Signal error on applicable method with invalid qualifiers,or on method combination. For control and args see format,p. 38.

    (gFno-next-method generic-function method arg∗)

    ⊲ Called on invocation of call-next-method when there is nonext method. Default method signals error.

    (gFfunction-keywords method)

    ⊲ Return list of keyword parameters of method and2T if other

    keys are allowed.

    (gFmethod-qualifiers method) ⊲ List of qualifiers of method .

    10.3 Method Combination Types

    standard⊲ Evaluate most specific :around method supplying the val-ues of the generic function. From within this method,Fucall-next-method can call less specific :around methods if thereare any. If not, or if there are no :around methods at all, callall :before methods, most specific first, and the most spe-cific primary method which supplies the values of the callingFucall-next-method if any, or of the generic function; and whichcan call less specific primary methods via

    Fucall-next-method.

    After its return, call all :after methods, least specific first.

    and or append list nconc progn max min +⊲ Simple built-in method-combination types; have thesame usage as the c-types defined by the short form ofMdefine-method-combination.

    27

  • Common Lisp Quick Reference

    Tatom

    readtable

    package

    symbol

    keyw

    ord

    boolean

    restart

    random-state

    hash-table

    structure-object

    standard-object

    null

    class

    built-in-class

    standard-class

    structure-class

    method

    standard-m

    ethod

    method-combination

    character

    function[ arg-types[value-types]]

    compiled-function

    generic-function

    standard-generic-function

    pathname

    logical-pathname

    number

    complex[type

    *]real[ lo

    wer-limit

    *[upper-limit *]]float[ lo

    wer-limit

    *[upper-limit *]]short-float[ lo

    wer-limit

    *[upper-limit *]]single-float[ lo

    wer-limit

    *[upper-limit *]]double-float[ lo

    wer-limit

    *[upper-limit *]]long-float[ lo

    wer-limit

    *[upper-limit *]]rational[ lo

    wer-limit

    *[upper-limit *]]integer[ lo

    wer-limit

    *[upper-limit *]]ratio

    signed-byte[size

    *] fixnumbignum

    unsigned-byte[size

    *] bit

    list

    sequence

    cons[ car-type

    *[cdr-type *]]array[ type

    *[rank *(dimension∗)]]

    simple-array

    [ type

    *[rank *(dimension∗)]]

    vector[ type

    *[size *]]string[size

    *]simple-string[size

    *]base-string[size

    *]simple-base-string[size

    *]simple-vector[size

    *]bit-vector[size

    *]simple-bit-vector[size

    *]

    stream

    file-stream

    two-w

    ay-stream

    synonym

    -stream

    string-stream

    broadca

    st-stream

    conca

    tenated-stream

    ech

    o-stream

    extended-char

    base-char

    standard-char

    condition

    serious-co

    ndition

    storage-condition

    simple-typ

    e-error

    type-error

    error program-error

    control-error

    package-error

    print-not-readable

    stream-error

    parse-error

    cell-error

    file-error

    arithmetic-error

    simple-condition

    warning

    style-w

    arning

    simple-error

    simple-w

    arning

    end-of-file

    reader-error

    unbound-variable

    undefined-function

    unbound-slot

    division-by-zero

    floating-point-inexa

    ct

    floating-point-ove

    rflow

    floating-point-underflow

    floating-point-inva

    lid-operation

    Figure 2: Precedence Order of System Classes ( ), Classes ( ),Types ( ), and Condition Types ( ).

    32

    Common Lisp Quick Reference

    ⊲ Define, as a subtype of parent-types, condition type foo.In a new condition, a slot ’s value defaults to form unless setvia :initarg-name; it is readable via (reader i) or (accessor i),and writeable via (writer value i) or (setf (accessor i) value).With :allocation :class, slot is shared by all conditions of typefoo. A condition is reported by string or by report-functionof arguments condition and stream.

    (Fumake-condition type {:initarg-name value}∗)

    ⊲ Return new condition of type .

    (

    FusignalFuwarnFuerror

    condition

    type {:initarg-name value}∗control arg∗

    )

    ⊲ Unless handled, signal as condition, warning or error,respectively, condition or a new condition of type or,with

    Fuformat control and args (see p. 38), simple-condition,

    simple-warning, or simple-error, respectively. FromFusignal and

    Fuwarn, return NIL.

    (Fucerror continue-control

    condition continue-arg∗

    type {:initarg-name value}∗control arg∗

    )

    ⊲ Unless handled, signal as correctable error condition or anew condition of type or, with

    Fuformat control and args (see

    p. 38), simple-error. In the debugger, useFuformat arguments

    continue-control and continue-args to tag the continue op-tion. Return NIL.

    (Mignore-errors form

    P∗)⊲ Return values of forms or, in case of errors, NIL and the

    2condition.

    (Fuinvoke-debugger condition)

    ⊲ Invoke debugger with condition .

    (Massert test

    [(place∗) [

    condition continue-arg∗

    type {:initarg-name value}∗control arg∗

    ]

    ])

    ⊲ If test , which may depend on places, returns NIL, signalas correctable error condition or a new condition of type or,with

    Fuformat control and args (see p. 38), error. When using

    the debugger’s continue option, places can be altered beforere-evaluation of test. Return NIL.

    (Mhandler-case foo (type ([var ]) (declare d̂ecl∗)∗ condition-form

    P∗)∗

    [(:no-error (ord-λ∗) (declare d̂ecl∗)∗ formP∗)])

    ⊲ If, on evaluation of foo, a condition of type is signalled,evaluate matching condition-forms with var bound to thecondition, and return their values. Without a condition, bindord-λs to values of foo and return values of forms or, withouta :no-error clause, return values of foo . See p. 18 for (ord-λ∗).

    (Mhandler-bind ((condition-type handler-function)∗) form

    P∗)⊲ Return values of forms after evaluating them withcondition-types dynamically bound to their respectivehandler-functions of argument condition.

    (Mwith-simple-restart (

    {restart

    NIL

    }control arg∗) form

    P∗)

    ⊲ Return values of forms unless restart is called during theirevaluation. In this case, describe restart using

    Fuformat control

    and args (see p. 38) and return NIL and2T.

    (Mrestart-case form (foo (ord-λ∗)

    ∣∣∣∣∣∣∣∣

    :interactive arg-function

    :report

    {report-function

    string "foo":test test-function T

    (declare d̂ecl∗)∗ restart-formP∗)∗)

    29

  • Common Lisp Quick Reference

    ⊲ Evaluate form with dynamically established restarts foo.Return values of form or, if by (

    Fuinvoke-restart foo arg∗) one

    restart foo is called, use string or report-function (of a stream)to print a description of restart foo and return the values ofits restart-forms. arg-function supplies appropriate args iffoo is called by

    Fuinvoke-restart-interactively. If (test-function

    condition) returns T, foo is made visible under condition .arg∗ matches (ord-λ∗); see p. 18 for the latter.

    (Mrestart-bind ((

    {r̂estart

    NIL

    }restart-function

    ∣∣∣∣∣∣

    :interactive-function function:report-function function:test-function function

    )

    ∗) formP∗)

    ⊲ Return values of forms evaluated with restarts dynamicallybound to restart-functions.

    (Fuinvoke-restart restart arg∗)(

    Fuinvoke-restart-interactively restart)

    ⊲ Call function associated with restart with arguments givenor prompted for, respectively. If restart function returns, re-turn its values.

    (

    { Fucompute-restartsFufind-restart name

    }[condition ])

    ⊲ Return list of all restarts, or innermost restart name, re-spectively, out of those either associated with condition orun-associated at all; or, without condition , out of all restarts.Return NIL if search is unsuccessful.

    (Furestart-name restart) ⊲ Name of restart .

    (

    FuabortFumuffle-warningFucontinueFustore-value valueFuuse-value value

    [condition NIL ])

    ⊲ Transfer control to innermost applicable restart with samename (i.e. abort, . . . , continue . . . ) out of those either as-sociated with condition or un-associated at all; or, withoutcondition , out of all restarts. If no restart is found, signalcontrol-error for

    Fuabort and

    Fumuffle-warning, or return NIL for

    the rest.

    (Mwith-condition-restarts condition restarts form

    P∗)⊲ Evaluate forms with restarts dynamically associated withcondition . Return values of forms.

    (Fuarithmetic-error-operation condition)(

    Fuarithmetic-error-operands condition)

    ⊲ List of function or of its operands respectively, used in theoperation which caused condition .

    (Fucell-error-name condition)

    ⊲ Name of cell which caused condition .

    (Fuunbound-slot-instance condition)

    ⊲ Instance with unbound slot which caused condition .

    (Fuprint-not-readable-object condition)

    ⊲ The object not readably printable under condition .

    (Fupackage-error-package condition)(

    Fufile-error-pathname condition)(

    Fustream-error-stream condition)

    ⊲ Package, path, or stream, respectively, which caused thecondition of indicated type.

    (Futype-error-datum condition)(

    Futype-error-expected-type condition)

    ⊲ Object which caused condition of type type-error, or itsexpected type, respectively.

    30

    Common Lisp Quick Reference

    (Fusimple-condition-format-control condition)(

    Fusimple-condition-format-arguments condition)

    ⊲ ReturnFuformat control or list of

    Fuformat arguments, respec-

    tively, of condition .var*break-on-signals*NIL

    ⊲ Condition type debugger is to be invoked on.

    var*debugger-hook*NIL⊲ Function of condition and function itself. Called beforedebugger.

    12 Types and Classes

    For any class, there is always a corresponding type of the samename.

    (Futypep foo type [environment NIL ]) ⊲ T if foo is of type.

    (Fusubtypep type-a type-b [environment ])

    ⊲ Return T if type-a is a recognizable subtype of type-b, and

    2NIL if the relationship could not be determined.

    (sOthe t̂ype form) ⊲ Declare values of form to be of type.

    (Fucoerce object type) ⊲ Coerce object into type.

    (Mtypecase foo (t̂ype a-form

    P∗)∗[(

    {otherwiseT

    }b-form NIL

    P∗)])

    ⊲ Return values of the a-forms whose type is foo of. Returnvalues of b-forms if no type matches.

    (

    {MctypecaseMetypecase

    }foo (t̂ype form

    P∗)∗)

    ⊲ Return values of the form s whose type is foo of. Sig-nal correctable/non-correctable error, respectively if no typematches.

    (Futype-of foo) ⊲ Type of foo .

    (Mcheck-type place type [string

    {a an} type])

    ⊲ Signal correctable type-error if place is not of type. ReturnNIL.

    (Fustream-element-type stream) ⊲ Return type of stream objects.

    (Fuarray-element-type array) ⊲ Element type array can hold.

    (Fuupgraded-array-element-type type [environment NIL ])

    ⊲ Element type of most specialized array capable of holdingelements of type.

    (Mdeftype foo (macro-λ∗) (declare d̂ecl∗)∗ [d̂oc] form

    P∗)⊲ Define type foo which when referenced as (foo ârg∗) ap-plies expanded forms to args returning the new type. For(macro-λ∗) see p. 19 but with default value of * instead ofNIL. forms are enclosed in an implicit

    sOblock named foo.

    (eql foo)(member foo∗)

    ⊲ Specifier for a type comprising foo or foos.

    (satisfies predicate)⊲ Type specifier for all objects satisfying predicate .

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

    (not type) ⊲ Complement of type.

    (and type∗ T ) ⊲ Type specifier for intersection of types.

    (or type∗ NIL ) ⊲ Type specifier for union of types.

    (values type∗[&optional type∗ [&rest other-args ]

    ])

    ⊲ Type specifier for multiple values.* ⊲ As a type argument (cf. Figure 2): no restriction.31

  • Common Lisp Quick Reference

    (gFprint-object object s̃tream)

    ⊲ Print object to stream . Called by the Lisp printer.

    (Mprint-unreadable-object (foo s̃tream

    {∣∣∣∣:type bool NIL:identity bool NIL

    }) form

    P∗)

    ⊲ Enclosed in #< and >, print foo by means of forms tostream . Return NIL.

    (Futerpri [s̃tream var*standard-output* ])

    ⊲ Output a newline to stream . Return NIL.

    (Fufresh-line) [s̃tream var*standard-output* ]

    ⊲ Output a newline to stream and return T unless stream isalready at the start of a line.

    (Fuwrite-char char [s̃tream var*standard-output* ])

    ⊲ Output char to stream .

    (

    { Fuwrite-stringFuwrite-line

    }string

    [s̃tream var*standard-output* [{∣∣∣∣:start start 0:end end NIL }]])

    ⊲ Write string to stream without/with a trailing newline.

    (Fuwrite-byte byte s̃tream) ⊲ Write byte to binary stream .

    (Fuwrite-sequence sequence s̃tream

    {∣∣∣∣:start start 0:end end NIL

    })

    ⊲ Write elements of sequence to binary or character stream .

    (

    { FuwriteFuwrite-to-string

    }foo

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :array bool:base radix

    :case

    :upcase:downcase:capitalize

    :circle bool:escape bool:gensym bool:length {int NIL}:level {int NIL}:lines {int NIL}:miser-width {int NIL}:pprint-dispatch dispatch-table:pretty bool:radix bool:readably bool

    :right-margin {int NIL}:stream s̃tream var*standard-output*

    )

    ⊲ Print foo to stream and return foo, or print foo into string,respectively, after dynamically setting printer variables corre-sponding to keyword parameters (*print-bar* becoming :bar).(:stream keyword with

    Fuwrite only.)

    (Fupprint-fill s̃tream foo

    [parenthesis T [noop]

    ])

    (Fupprint-tabular s̃tream foo

    [parenthesis T [noop [n 16 ]]

    ])

    (Fupprint-linear s̃tream foo

    [parenthesis T [noop]

    ])

    ⊲ Print foo to stream . If foo is a list, print as many elementsper line as possible; do the same in a table with a columnwidth of n ems; or print either all elements on one line oreach on its own line, respectively. Return NIL. Usable withFuformat directive ˜//.

    (Mpprint-logical-block (s̃tream list

    ∣∣∣∣∣∣

    {:prefix string:per-line-prefix string

    }

    :suffix string ""

    )

    (declare d̂ecl∗)∗ formP∗)

    ⊲ Evaluate forms, which should print list , with stream lo-cally bound to a pretty printing stream which outputs to theoriginal stream. If list is in fact not a list, it is printed byFuwrite. Return NIL.

    36

    Common Lisp Quick Reference

    13 Input/Output

    13.1 Predicates

    (Fustreamp foo)(

    Fupathnamep foo)(

    Fureadtablep foo)

    ⊲ T if foo is of indicated type.

    (Fuinput-stream-p stream)(

    Fuoutput-stream-p stream)(

    Fuinteractive-stream-p stream)(

    Fuopen-stream-p stream)

    ⊲ Return T if stream is for input, for output, interactive, oropen, respectively.

    (Fupathname-match-p path wildcard )

    ⊲ T if path matches wildcard .

    (Fuwild-pathname-p path

    [{:host :device :directory :name :type :version

    NIL}])

    ⊲ Return T if indicated component in path is wildcard. (NILindicates any component.)

    13.2 Reader

    (

    { Fuy-or-n-pFuyes-or-no-p

    }[control arg∗])

    ⊲ Ask user a question and return T or NIL depending on theiranswer. See p. 38,

    Fuformat, for control and args.

    (Mwith-standard-io-syntax form

    P∗)⊲ Evaluate forms with standard behaviour of reader andprinter. Return values of forms.

    (

    { FureadFuread-preserving-whitespace

    } [s̃tream var*standard-input* [eof-err T

    [eof-val NIL [recursive NIL ]]]])

    ⊲ Read printed representation of object.

    (Furead-from-string string

    [eof-error T

    [eof-val NIL

    [

    ∣∣∣∣∣∣

    :start start 0:end end NIL:preserve-whitespace bool NIL

    ]]]

    )

    ⊲ Return object read from string and zero-indexed2position

    of next character.

    (Furead-delimited-list char

    [s̃tream var*standard-input* [recursive NIL ]])

    ⊲ Continue reading until encountering char . Return list ofobjects read. Signal error if no char is found in stream.

    (Furead-char

    [s̃tream var*standard-input* [eof-err T [eof-val NIL

    [recursive NIL ]]]])

    ⊲ Return next character from stream.

    (Furead-char-no-hang

    [s̃tream var*standard-input* [eof-error T [eof-val NIL

    [recursive NIL ]]]])

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

    (Fupeek-char

    [mode NIL

    [s̃tream var*standard-input* [eof-error T [eof-val NIL

    [recursive NIL ]]]]]

    )⊲ Next, or if mode is T, next non-whitespace character, or ifmode is a character, next instance of it, from stream withoutremoving it there.

    (Fuunread-char character [s̃tream var*standard-input* ])

    ⊲ Put lastFuread-chared character back into stream; return

    NIL.

    (Furead-byte s̃tream

    [eof-err T [eof-val NIL ]

    ])

    ⊲ Read next byte from binary stream.

    33

  • Common Lisp Quick Reference

    (Furead-line

    [s̃tream var*standard-input* [eof-err T [eof-val NIL

    [recursive NIL ]]]])

    ⊲ Return a line of text from stream and2T if line has been

    ended by end of file.

    (Furead-sequence ˜sequence s̃tream [:start start 0 ][:end end NIL ])

    ⊲ Replace elements of sequence between start and end withelements from binary or character stream. Return index ofsequence’s first unmodified element.

    (Fureadtable-case readtable) :upcase

    ⊲ Case sensitivity attribute (one of :upcase, :downcase,:preserve, :invert) of readtable . setfable.

    (Fucopy-readtable

    [from-readtable var*readtable* [ ˜to-readtable NIL ]])

    ⊲ Return copy of from-readtable .

    (Fuset-syntax-from-char to-char from-char

    [˜to-readtable var*readtable*

    [from-readtable standard readtable ]])

    ⊲ Copy syntax of from-char to to-readtable . Return T.

    var*readtable* ⊲ Current readtable.var*read-base*10 ⊲ Radix for reading integers and ratios.var*read-default-float-format*single-float

    ⊲ Floating point format to use when not indicated in thenumber read.

    var*read-suppress*NIL⊲ If T, reader is syntactically more tolerant.

    (Fuset-macro-character char function

    [non-term-p NIL [r̃t var*readtable* ]])

    ⊲ Make char a macro character associated with function ofstream and char . Return T.

    (Fuget-macro-character char [rt var*readtable* ])

    ⊲ Reader macro function associated with char , and2T if char

    is a non-terminating macro character.

    (Fumake-dispatch-macro-character char

    [non-term-p NIL [rt var*readtable* ]])

    ⊲ Make char a dispatching macro character. Return T.

    (Fuset-dispatch-macro-character char sub-char function [r̃t var*readtable* ])

    ⊲ Make function of stream, n, sub-char a dispatch functionof char followed by n , followed by sub-char . Return T.

    (Fuget-dispatch-macro-character char sub-char [rt var*readtable* ])

    ⊲ Dispatch function associated with char followed bysub-char .

    13.3 Character Syntax

    #| multi-line-comment∗ |#; one-line-comment∗

    ⊲ Comments. There are stylistic conventions:

    ;;;; title ⊲ Short title for a block of code.

    ;;; intro ⊲ Description before a block of code.

    ;; state ⊲ State of program or of following code.

    ;explanation; continuation

    ⊲ Regarding line on which it appears.

    (foo∗[ . bar NIL ]) ⊲ List of foos with the terminating cdr bar .

    ” ⊲ Begin and end of a string.

    ’foo ⊲ (sOquote foo); foo unevaluated.

    34

    Common Lisp Quick Reference

    `([foo] [,bar ] [,@baz ] [,.q̃uux ] [bing])⊲ Backquote.

    sOquote foo and bing ; evaluate bar and splice

    the lists baz and quux into their elements. When nested,outermost commas inside the innermost backquote expressionbelong to this backquote.

    #\c ⊲ (Fucharacter "c"), the character c.

    #Bn ; #On; n.; #Xn ; #rRn⊲ Integer of radix 2, 8, 10, 16, or r ; 2 ≤ r ≤ 36.

    n/d ⊲ The ratio nd.

    {[m].n

    [{S F D L E}x E0

    ]m[.[n]

    ]{S F D L E}x

    }

    ⊲ m.n ·10x as short-float, single-float, double-float, long-float,or the type from *read-default-float-format*.

    #C(a b) ⊲ (Fucomplex a b), the complex number a + bi.

    #’foo ⊲ (sOfunction foo); the function named foo.

    #nAsequence ⊲ n-dimensional array.

    #[n ](foo∗)⊲ Vector of some (or n) foos filled with last foo if necessary.

    #[n ]*b∗⊲ Bit vector of some (or n) bs filled with last b if necessary.

    #S(type {slot value}∗) ⊲ Structure of type.

    #Pstring ⊲ A pathname.

    #:foo ⊲ Uninterned symbol foo.

    #.form ⊲ Read-time value of form.

    var*read-eval*T ⊲ If NIL, a reader-error is signalled at #..#integer= foo ⊲ Give foo the label integer .

    #integer# ⊲ Object labelled integer .

    #< ⊲ Have the reader signal reader-error.

    #+feature when-feature#–feature unless-feature

    ⊲ Means when-feature if feature is T; means unless-feature iffeature is NIL. feature is a symbol from

    var*features*, or ({andor} feature∗), or (not feature).

    var*features*⊲ List of symbols denoting implementation-dependent fea-tures.

    |c∗|; \c⊲ Treat arbitrary character(s) c as alphabetic preservingcase.

    13.4 Printer

    (

    Fuprin1FuprintFupprintFuprinc

    foo [s̃tream var*standard-output* ])⊲ Print foo to stream

    Fureadably,

    Fureadably between a newline

    and a space,Fureadably after a newline, or human-readably

    without any extra characters, respectively.Fuprin1,

    Fuprint and

    Fuprinc return foo.

    (Fuprin1-to-string foo)(

    Fuprinc-to-string foo)

    ⊲ Print foo to stringFureadably or human-readably, respec-

    tively.

    35

  • Common Lisp Quick Reference

    ˜[prefix {,prefix}∗

    ][:] [@] /

    [package :[:]cl-user:

    ]function/

    ⊲ Call Function. Call all-uppercase package::functionwith the arguments stream, format-argument, colon-p,at-sign-p and prefixes for printing format-argument.

    ˜ [:] [@] W⊲ Write. Print argument of any type obeying everyprinter control variable. With :, pretty-print. With @,print without limits on length or depth.

    {V #}⊲ In place of the comma-separated prefix parameters:use next argument or number of remaining unprocessedarguments, respectively.

    13.6 Streams

    (Fuopen path

    ∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣∣

    :direction

    :input:output:io:probe

    :input

    :element-type

    {type

    :default

    }character

    :if-exists

    :new-version:error:rename:rename-and-delete:overwrite:append:supersedeNIL

    :new-version if pathspecifies :newest;NIL otherwise

    :if-does-not-exist

    :error:createNIL

    NIL for :direction :probe;

    {:create :error} otherwise

    :external-format format :default

    )

    ⊲ Open file-stream to path .

    (Fumake-concatenated-stream input-stream∗)(

    Fumake-broadcast-stream output-stream∗)(

    Fumake-two-way-stream input-stream-part output-stream-part )(

    Fumake-echo-stream from-input-stream to-output-stream)(

    Fumake-synonym-stream variable-bound-to-stream)

    ⊲ Return stream of indicated type.

    (Fumake-string-input-stream string

    [start 0 [end NIL ]

    ])

    ⊲ Return a string-stream supplying the characters fromstring .

    (Fumake-string-output-stream [:element-type type character ])

    ⊲ Return a string-stream accepting characters (available viaFuget-output-stream-string).

    (Fuconcatenated-stream-streams concatenated-stream)(

    Fubroadcast-stream-streams broadcast-stream )

    ⊲ Return list of streams concatenated-stream still has to readfrom/broadcast-stream is broadcasting to.

    (Futwo-way-stream-input-stream two-way-stream)(

    Futwo-way-stream-output-stream two-way-stream)(

    Fuecho-stream-input-stream echo-stream)(

    Fuecho-stream-output-stream echo-stream)

    ⊲ Return source stream or sink stream of two-way-stream/echo-stream , respectively.

    (Fusynonym-stream-symbol synonym-stream)

    ⊲ Return symbol of synonym-stream .

    (Fuget-output-stream-string ˜string-stream)

    ⊲ Clear and return as a string characters on string-stream.

    (Fufile-position stream [

    :start:endposition

    ])

    ⊲ Return position within stream, or set it to position andreturn T on success.

    40

    Common Lisp Quick Reference

    (Mpprint-pop)

    ⊲ Take next element off list . If there is no remaining tailof list , or

    var*print-length* or var*print-circle* indicate printingshould end, send element together with an appropriateindicator to stream .

    (Fupprint-tab

    :line:line-relative:section:section-relative

    c i [s̃tream var*standard-output* ])⊲ Move cursor forward to column number c + ki, k ≥ 0being as small as possibl