There are 234 utilities.
- octet v1.0
-
A type representing an octet: 8 bits. If a positive integer
n
is specified, then(octet n)
represents8n
bits. This can often be used for optimization in Common Lisp.- Provides
octet
- positivep v1.0
-
Check if
n
is positive.- Provides
positivep
- negativep v1.0
-
Check if
n
is negative.- Provides
negativep
- non-negative-p v1.0
-
Check if
n
is non-negative.- Provides
non-negative-p
- non-positive-p v1.0
-
Check if
n
is non-positive.- Provides
non-positive-p
- non-zero-p v1.0
-
Check if
n
is non-zero.- Provides
non-zero-p
- digit-count v2.0
-
Compute the number of digits in the non-negative integer
n
in basebase
. By default, the base is 10.- Provides
digit-count
- range-product v1.0
-
Compute
lower * (lower+1) * ... * (upper-1) * upper
.- Provides
range-product
- factorial v1.0
-
Compute the factorial of
n
, wheren! = 1 * 2 * ... * n
.- Provides
factorial
- Requires
- range-product
- binomial-coefficient v1.0
-
Binomial coefficient of
n
andk
.- Provides
binomial-coefficient
- Requires
- factorial, range-product
- mulf v1.0
-
A modifying version of multiplication, similar to
incf
.- Provides
mulf
- divf v1.0
-
A modifying version of division, similar to
decf
.- Provides
divf
- half v1.0
-
Compute half of
x
.- Provides
half
- double v1.0
-
Compute double
x
.- Provides
double
- square v1.0
-
Compute the square of
x
.- Provides
square
- cube v1.0
-
Compute the cube of
x
.- Provides
cube
- digits v1.0
-
Return a list of the digits of the non-negative integer
n
in basebase
. By default, decimal digits are returned.The order of the digits is such that the
k
th element of the list refers to the coefficient ofbase^k
. In other words, given the resulting list(c0 c1 c2 ... ck)
the following identity holds:
n = c0 + c1*base + c2*base^2 + ... + ck*base^k.
- Provides
digits
- nth-digit v1.0
-
Get the
n
th digit in a rational numbernumber
in basebase
. Ifn
is positive, it refers to digits to the left of the decimal point, and if negative, to the right. The digits of a negative number match that of its positive counterpart.- Provides
nth-digit
- bit-vector-integer v1.0
-
Convert a bit vector
bv
to a positive integer. The bits of the integer are ordered from most significant to least significant, unlessleast-significant-first
is true.- Provides
bit-vector-integer
- integer-bit-vector v1.0
-
Convert a positive integer
n
to a bit vector. The least significant bits will be first ifleast-significant-first
is true.- Provides
integer-bit-vector
- primes-below v1.0
-
Return a sorted list of all primes below an integer
n
.Examples:
(primes-below 13) => (2 3 5 7 11) (primes-below -1) => NIL
- Provides
primes-below
- sec v1.0
-
Compute the secant of a number
z
.- Provides
sec
- csc v1.0
-
Compute the cosecant of a number
z
.- Provides
csc
- cot v1.0
-
Compute the cotangent of a number
z
.- Provides
cot
- asec v1.0
-
Compute the arcsecant of a number
z
.- Provides
asec
- acsc v1.0
-
Compute the arccosecant of a number
z
.- Provides
acsc
- acot v1.0
-
Compute the arccotangent of a number
z
.- Provides
acot
- sort-copy v1.0
-
Copying versions of
cl:sort
andcl:stable-sort
.- Provides
sort-copy
,stable-sort-copy
- take v1.0
-
Take the first
n
elements fromsequence
.- Provides
take
- drop v1.0
-
Drop the first
n
elements fromsequence
.- Provides
drop
- subdivide v1.0
-
Split
sequence
into subsequences of sizechunk-size
.- Provides
subdivide
- n-grams v1.0
-
Find all
n
-grams of the sequencesequence
.- Provides
n-grams
- Requires
- take
- partition-if v1.0
-
Partition sequences based off of a predicate.
- Provides
partition-if
,partition-if-not
- equivalence-classes v1.0
-
Partition the sequence
seq
into a list of equivalence classes defined by the equivalence relationequiv
.- Provides
equivalence-classes
- doseq v1.0
-
Iterate across the sequence
seq
, binding the variablevar
to each element of the sequence and executingbody
. Return the valuereturn
from the iteration form.- Provides
doseq
- range v1.0
-
Return the list of numbers
n
such thatstart <= n < end
andn = start + k*step
for suitable integersk
. If a functionkey
is provided, then apply it to each number.- Provides
range
- replicate v1.0
-
Make a list of
n
copies ofx
.- Provides
replicate
- slice v1.0
-
Compute the slice of a list
list
at indexesindexes
.- Provides
slice
- transpose v1.0
-
Analog to matrix transpose for a list of lists given by
lists
.- Provides
transpose
- zip v1.0
-
Take a tuple of lists and turn them into a list of tuples. Equivalent to
unzip
.- Provides
zip
- Requires
- transpose
- unzip v1.0
-
Take a list of tuples and return a tuple of lists. Equivalent to
zip
.- Provides
unzip
- Requires
- transpose
- long-zip v1.0
-
zip
using the longest, rather than shortest list, filling withfill
.- Provides
long-zip
- Requires
- zip
- enumerate v1.0
-
Equivalent to
(zip (iota (length list)) list)
.- Provides
enumerate
- flatten-once v1.0
-
Flatten
list
once.- Provides
flatten-once
- flatten-tagged-once v1.0
-
Flatten once a list
x
with a tagtag
.- Provides
flatten-tagged-once
- flatten v1.0
-
Flatten (and append) all lists
xs
completely.- Provides
flatten
- ncycle v1.0
-
Mutate
list
into a circlular list.- Provides
ncycle
- cycle v1.0
-
Make
list
into a circular list.- Provides
cycle
- Requires
- ncycle
- nest v1.0
-
Compute a
count
compositions offunction
oninitial-value
.- Provides
nest
- nest-list v1.0
-
Compute a list of
count
compositions offunction
oninitial-value
.- Provides
nest-list
- safe-nth v1.0
-
Find the
n
th element oflist
. Ifn
is out of bounds, returnif-out-of-bounds
(nil
by default).- Provides
safe-nth
- mapply v1.0
-
Apply
f
to each list of arguments contained withinlist
and collect the results.- Provides
mapply
- cartesian-product v1.0
-
Compute the cartesian product of
l1
andl2
as if they were sets. Optionally, map the functionf
across the product.- Provides
cartesian-product
- end v1.0
-
Return the last element of
list
and whether or not it was empty.- Provides
end
- tabulate v1.0
-
Return a list evaluations of
f
over the integers[0,n)
. Mimics the SML function of the same name.- Provides
tabulate
- Requires
- range
- collect-reduce v1.0
-
Collects intermediate reduction results of applying
f
tolist
. More or less equivalent to(loop :for i :in list :collect (reduce f i))
.- Provides
collect-reduce
- weave v1.0
-
Return a list whose elements alternate between each of the lists
lists
. Weaving stops when any of the lists has been exhausted.- Provides
weave
- interleave v1.0
-
Return a list whose elements alternate between each of the lists
lists
. When a list has been exhausted, interleaving continues with whatever other non-empty lists.- Provides
interleave
- riffle v1.0
-
Insert the item
obj
in between each element oflist
.- Provides
riffle
- extend v1.0
-
Adjoin
x
to the end ofxs
.- Provides
extend
- list-to-vector v1.0
-
Convert
list
into a vector.- Provides
list-to-vector
- sequence-to-list v1.0
-
Convert the sequence
seq
into a list.- Provides
sequence-to-list
- explode v1.0
-
The classic
explode
function. Take a string and return a list of its characters.- Provides
explode
- Requires
- sequence-to-list
- implode v1.0
-
The classic
implode
function. Take a list of characters and return the corresponding string.- Provides
implode
- Requires
- list-to-vector
- inits v1.0
-
Generate a list of initial sublists of the list
list
. The nameinits
comes from the Haskell function of the same name.Example:
> (inits '(a b c d)) (NIL (A) (A B) (A B C) (A B C D))
- Provides
inits
- tails v1.0
-
Generate a list of tails of the list
list
. The nametails
comes from the Haskell function of the same name.Example
> (tails '(a b c d)) ((A B C D) (B C D) (C D) (D) NIL)
- Provides
tails
- string-append v1.0
-
Append strings or a sequence of strings together.
- Provides
string-append
,string-append*
- separated-string-append v1.0
-
Append strings or a sequence of strings, separated by a separator.
- Provides
separated-string-append
,separated-string-append*
- string-append-space v1.0
-
Concatenate
strings
separated by a single space.- Provides
string-append-space
- Requires
- separated-string-append
- fix v1.0
-
Apply the fixed-point combinator, also known as the Y-combinator, to the function
F : (A -> B) -> A -> B
.- Provides
fix
- flip v1.0
-
Return a function whose argument order of a binary function
f
is reversed.- Provides
flip
- applyable v1.0
-
Given a function
fun
, return a variadic function which results infun
being called on the passed argument list. (Note:fun
will not be applied to the passed argument list.)The resulting function is able to be applied to lists as a result (hence "appliable").
- Provides
applyable
- applying v1.0
-
Given a function
fun
, return a unary function whose result is applyingfun
to the single argument.- Provides
applying
- compose-apply v1.0
-
Create a variadic function whose result is applying the function
fun
to results obtained by applying each offuns
to the argument list.Example:
` (defvar average-values (compose-apply '/ '+ (applyable 'length))) (defvar average-list (compose-apply '/ (applying '+) 'length))
(funcall average-values 1 2 3) => 2 (funcall average-list '(1 2 3) => 2 ```
- Provides
compose-apply
- rerank-array v1.0
-
Reshape
array
to have dimensions specified bydimensions
, possibly with a different rank than the original. The dimensions ofarray
and the givendimensions
must have the same total number of elements.- Provides
rerank-array
- vector-range v1.0
-
Compute the equivalent of
(coerce (range a b :step step) 'vector)
.- Provides
vector-range
- vector-slice v1.0
-
Compute the slice of a vector
v
at indexesindexes
.- Provides
vector-slice
- vector-associative-reduce v1.0
-
Reduce
vector
withassociative-function
, using a divide-and-conquer method.- Provides
vector-associative-reduce
- array-contents v1.0
-
Extract the contents of the array
array
, returning a value that would be suitable to pass to the:initial-contents
keyword argument ofmake-array
.- Provides
array-contents
- execution-time v1.0
-
Return the number of milliseconds it takes to execute
body
. Also returns the result as the second value.- Provides
execution-time
- map-tree v1.0
-
Map
function
to each of the leave oftree
.- Provides
map-tree
- tree-member-p v1.0
-
Returns
t
ifitem
is intree
,nil
otherwise.- Provides
tree-member-p
- tree-collect v1.0
-
Returns a list of every node in the
tree
that satisfies thepredicate
. If there are any improper lists in the tree, thepredicate
is also applied to their dotted elements.- Provides
tree-collect
- same-name v1.0
-
Do symbols
a
andb
have the same name?- Provides
same-name
- ensure-keyword v1.0
-
Ensure that a keyword is returned for the string designator
x
.- Provides
ensure-keyword
- mkstr v1.0
-
Receives any number of objects (string, symbol, keyword, char, number), extracts all printed representations, and concatenates them all into one string.
Extracted from On Lisp, chapter 4.
- Provides
mkstr
- symb v1.0
-
Receives any number of objects, concatenates all into one string with
#'mkstr
and converts them to symbol.Extracted from On Lisp, chapter 4.
See also:
symbolicate
- Provides
symb
- Requires
- mkstr
- void v1.0
-
Do absolutely nothing, and return absolutely nothing.
- Provides
void
- ensure-boolean v1.0
-
Convert
x
into a Boolean value.- Provides
ensure-boolean
- letf* v1.0
-
Given a list of
bindings
whose keys are places and whose values are forms, set them for the duration ofbody
, but restore their values (as visible upon evaluation of this macro) upon completion. The restoration is ensured withunwind-protect
.- Provides
letf*
- Requires
- zip, appendf
- let1 v1.0
-
Bind VAR to VAL within BODY. Equivalent to LET with one binding.
- Provides
let1
- defaccessor v1.0
-
Define the function named
name
just as with a normaldefun
. Also define the setter(setf name)
. The form to be set (i.e., the place) should be wrapped in the local macroaccesses
. For example,CL-USER> (let ((x 0)) (defaccessor saved-x () (accesses x))) SAVED-X (SETF SAVED-X) CL-USER> (saved-x) 0 CL-USER> (setf (saved-x) 5) 5 CL-USER> (saved-x) 5
- Provides
defaccessor
,accesses
- Requires
- with-gensyms, parse-body
- imaginary-i v1.0
-
The imaginary number
i = sqrt(-1)
.- Provides
imaginary-i
,ii
- exponential-e v1.0
-
The exponential number
e = 2.71828...
.- Provides
exponential-e
,ee
- until v1.0
-
Executes
body
untilexpression
is true.- Provides
until
- while v1.0
-
Executes
body
whileexpression
is true.- Provides
while
- Requires
- until
- alist-to-hash-table v1.0
-
Create a hash table populated with
kv-pairs
.- Provides
alist-to-hash-table
- hash-table-key-exists-p v1.0
-
Does
key
exist inhash-table
?- Provides
hash-table-key-exists-p
- dohash v1.0
-
Iterate over the hash table
table
, executingbody
, withkey
andvalue
bound to the keys and values of the hash table respectively. Returnresult
from the iteration form.- Provides
dohash
- reseed-random-state v1.0
-
Reseed the random state use by the random number generator.
- Provides
reseed-random-state
- random-between v1.0
-
Generate a random integer between
a
andb
, inclusive.- Provides
random-between
- emptyp v1.0
-
Determine if
object
is empty.- Provides
emptyp
- Requires
- non-zero-p
- singletonp v1.0
-
Determine if
object
is a singleton object.- Provides
singletonp
- recons v1.0
-
Reuse the cons cell
old-cons
, replacing its CAR witha
and CDR withb
.- Provides
recons
- copy-cons v1.0
-
Copy the cons cell
c
.- Provides
copy-cons
- coerce-to-condition v1.0
-
This function implements the semantics of CL condition designators. It makes a condition, given a
datum
(which may be a symbol, format control, or condition) and a list of argumentsargs
. See CLHS 9.1.2.1 for more specifics.default-type
is the type of objects that should be constructed whendatum
is a format control.supertype
is a type that should be a supertype of the types of all conditions returned by this function.- Provides
coerce-to-condition
- true-false v1.0
-
true
andfalse
synonyms fort
andnil
.- Provides
true
,false
- yes-no v1.0
-
Always return
t
ornil
. Equivalent to(constantly t)
and(constantly nil)
.- Provides
yes
,no
- stream-direction v1.0
-
Return the direction of the stream
stream
::input
,:output
, or:io
.- Provides
stream-direction
- make-null-stream v1.0
-
Null input and output stream constructors.
- Provides
make-null-input-stream
,make-null-output-stream
,make-null-stream
- matching-null-stream v1.0
-
Return a null stream whose direction matches
stream
.- Provides
matching-null-stream
- Requires
- make-null-stream, stream-direction
- with-ignored-streams v1.0
-
Ignore any input or output to any of the streams denoted by the symbols
streams
in the codebody
.- Provides
with-ignored-streams
- Requires
- matching-null-stream
- quietly v1.0
-
Quietly execute
body
, suppressing all output.- Provides
quietly
- Requires
- with-ignored-streams
- skip-if v1.0
-
Given a character predicate
char-predicate
, read past all of the characters of the character streamstream
which satisfy that predicate. Optional argumentseof-error-p
,eof-value
, andrecursive-p
are the same as inread-char
.- Provides
skip-if
- skip v1.0
-
Read past all of the characters matching
char
in the character streamstream
. Optional argumentseof-error-p
,eof-value
, andrecursive-p
are the same as inread-char
.- Provides
skip
- Requires
- skip-if
- syntax-bind v1.0
-
Set
*readtable*
to a copy ofreadtable-expression
and modify the copy. Becausecl:load
andcl:compile-file
bind*readtable*
, this effectively gives a file local readtable in the same waycl:in-package
gives a file local binding to*package*
. Example call:(syntax-bind *convenient-readtable* (#\# #\@) 'send-line-to-channel #\! 'not-reader)
Sets
#!
to a nonterminating macro character. Use(#!)
to set it to a terminating macro character. A nullreadtable-expression
creates a readtable with standard Common Lisp syntax then applies the character bindings.- Provides
syntax-bind
- split-sequence v1.0
-
Split sequences into a list of subsequences based off of a delimiter or function.
- Provides
split-sequence
,split-sequence-if
,split-sequence-if-not
- define-constant v1.0
-
Ensures that the global variable named by
name
is a constant with a value that is equal undertest
to the result of evaluatinginitial-value
.test
is a function designator that defaults toeql
. Ifdocumentation
is given, it becomes the documentation string of the constant.Signals an error if
name
is already a bound non-constant variable.Signals an error if
name
is already a constant variable whose value is not equal undertest
to result of evaluatinginitial-value
.- Provides
define-constant
- if-let v1.0
-
Creates new variable bindings, and conditionally executes either
then-form
orelse-form
.else-form
defaults tonil
.bindings
must be either single binding of the form:(variable initial-form)
or a list of bindings of the form:
((variable-1 initial-form-1) (variable-2 initial-form-2) ... (variable-n initial-form-n))
All initial-forms are executed sequentially in the specified order. Then all the variables are bound to the corresponding values.
If all variables were bound to true values, the
then-form
is executed with the bindings in effect, otherwise theelse-form
is executed with the bindings in effect.- Provides
if-let
- when-let v1.0
-
Creates new variable bindings, and conditionally executes a series of forms.
- Provides
when-let
,when-let*
- string-designator v1.0
-
A string designator type. A string designator is either a string, a symbol, or a character.
- Provides
string-designator
- required-argument v1.0
-
Signals an error for a missing argument of
name
. Intended for use as an initialization form for structure and class-slots, and a default value for required keyword arguments.- Provides
required-argument
- simple-style-warning v1.0
-
- Provides
simple-style-warning
- simple-reader-error v1.0
-
- Provides
simple-reader-error
- simple-parse-error v1.0
-
- Provides
simple-parse-error
- simple-program-error v1.0
-
- Provides
simple-program-error
- ignore-some-conditions v1.0
-
Similar to
cl:ignore-errors
but the (unevaluated)conditions
list determines which specific conditions are to be ignored.- Provides
ignore-some-conditions
- unwind-protect-case v1.0
-
Like
cl:unwind-protect
, but you can specify the circumstances that the cleanupclauses
are run.clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*
Clauses can be given in any order, and more than one clause can be given for each circumstance. The clauses whose denoted circumstance occured, are executed in the order the clauses appear.
abort-flag
is the name of a variable that will be bound tot
inclauses
if theprotected-form
aborted preemptively, and tonil
otherwise.Examples:
(unwind-protect-case () (protected-form) (:normal (format t "This is only evaluated if PROTECTED-FORM executed normally.~%")) (:abort (format t "This is only evaluated if PROTECTED-FORM aborted preemptively.~%")) (:always (format t "This is evaluated in either case.~%"))) (unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p)))
- Provides
unwind-protect-case
- copy-hash-table v1.0
-
Returns a copy of hash table
table
, with the same keys and values as thetable
. The copy has the same properties as the original, unless overridden by the keyword arguments.Before each of the original values is set into the new hash-table,
key
is invoked on the value. Askey
defaults tocl:identity
, a shallow copy is returned by default.- Provides
copy-hash-table
- maphash-keys v1.0
-
Like
maphash
, but callsfunction
with each key in the hash tabletable
.- Provides
maphash-keys
- maphash-values v1.0
-
Like
maphash
, but callsfunction
with each value in the hash tabletable
.- Provides
maphash-values
- hash-table-keys v1.0
-
Returns a list containing the keys of hash table
table
.- Provides
hash-table-keys
- Requires
- maphash-keys
- hash-table-values v1.0
-
Returns a list containing the values of hash table
table
.- Provides
hash-table-values
- Requires
- maphash-values
- hash-table-alist v1.0
-
Returns an association list containing the keys and values of hash table
table
.- Provides
hash-table-alist
- hash-table-plist v1.0
-
Returns a property list containing the keys and values of hash table
table
.- Provides
hash-table-plist
- alist-hash-table v1.0
-
Returns a hash table containing the keys and values of the association list
alist
. Hash table is initialized using thehash-table-initargs
.- Provides
alist-hash-table
- plist-hash-table v1.0
-
Returns a hash table containing the keys and values of the property list
plist
. Hash table is initialized using thehash-table-initargs
.- Provides
plist-hash-table
- ensure-gethash v1.0
-
Like
gethash
, but ifkey
is not found in thehash-table
saves thedefault
under key before returning it. Secondary return value is true if key was already in the table.- Provides
ensure-gethash
- ensure-symbol v1.0
-
Returns a symbol with name designated by
name
, accessible in package designated bypackage
. If symbol is not already accessible inpackage
, it is interned there. Returns a secondary value reflecting the status of the symbol in the package, which matches the secondary return value ofintern
.Example:
(ensure-symbol :cons :cl) => cl:cons, :external
- Provides
ensure-symbol
- format-symbol v1.0
-
Constructs a string by applying
arguments
to string designatorcontrol
as if byformat
withinwith-standard-io-syntax
, and then creates a symbol named by that string.If
package
isnil
, returns an uninterned symbol, if package ist
, returns a symbol interned in the current package, and otherwise returns a symbol interned in the package designated bypackage
.- Provides
format-symbol
- make-keyword v1.0
-
Interns the string designated by
name
in thekeyword
package.- Provides
make-keyword
- make-gensym v1.0
-
If
name
is a non-negative integer, callsgensym
using it. Otherwisename
must be a string designator, in which case callsgensym
using the designated string as the argument.- Provides
make-gensym
- make-gensym-list v1.0
-
Returns a list of
length
gensyms, each generated as if with a call tomake-gensym
, using the second (optional, defaulting to"G"
) argument.- Provides
make-gensym-list
- symbolicate v1.0
-
Concatenate together the names of some strings and symbols, producing a symbol in the current package.
- Provides
symbolicate
- with-gensyms v1.0
-
Binds each variable named by a symbol in
names
to a unique symbol aroundforms
. Each ofnames
must either be either a symbol, or of the form:(symbol string-designator)
Bare symbols appearing in
names
are equivalent to:(symbol symbol)
The string-designator is used as the argument to
gensym
when constructing the unique symbol the named variable will be bound to.- Provides
with-gensyms
,with-unique-names
- Requires
- string-designator
- once-only v1.0
-
Evaluates
forms
with symbols specified inspecs
rebound to temporary variables, ensuring that each initform is evaluated only once.Each of
specs
must either be a symbol naming the variable to be rebound, or of the form:(symbol initform)
Bare symbols in
specs
are equivalent to(symbol symbol)
Example:
(defmacro cons1 (x) (once-only (x) `(cons ,x ,x))) (let ((y 0)) (cons1 (incf y))) => (1 . 1)
- Provides
once-only
- Requires
- make-gensym-list
- parse-body v1.0
-
Parses
body
into(values remaining-forms declarations doc-string)
. Documentation strings are recognized only ifdocumentation
is true. Syntax errors in body are signalled andwhole
is used in the signal arguments when given.- Provides
parse-body
- parse-ordinary-lambda-list v1.0
-
Parses an ordinary lambda-list, returning as multiple values:
Required parameters.
Optional parameter specifications, normalized into form:
(name init suppliedp)
Name of the rest parameter, or
nil
.Keyword parameter specifications, normalized into form:
((keyword-name name) init suppliedp)
Boolean indicating
&allow-other-keys
presence.&aux
parameter specifications, normalized into form
(name init)
.- Existence of
&key
in thelambda-list
.
Signals a
program-error
iflambda-list
is malformed.- Provides
parse-ordinary-lambda-list
- Requires
- simple-program-error, ensure-list, make-keyword
- destructuring-case v1.0
-
destructuring-case
, 'destructuring-ccaseand 'destructuring-ecase
are a combination ofcase
anddestructuring-bind
.keyform
must evaluate to afcons
.Clauses are of the form:
((case-keys . destructuring-lambda-list) form*)
The clause whose
case-keys
matchescar
ofkey
, as if bycase
,ccase
, orecase
, is selected, andform
s are then executed withcdr
ofkey
is destructured and Bound By Thedestructuring-lambda-list
.Example:
(defun dcase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar, ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)) ((t &rest rest) (format nil "unknown: ~S" rest)))) (dcase (list :foo 1 2)) ; => "foo: 1, 2" (dcase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (dcase (list :alt1 1)) ; => "alt: 1" (dcase (list :alt2 2)) ; => "alt: 2" (dcase (list :quux 1 2 3)) ; => "unknown: 1, 2, 3" (defun decase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar, ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)))) (decase (list :foo 1 2)) ; => "foo: 1, 2" (decase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase (list :alt1 1)) ; => "alt: 1" (decase (list :alt2 2)) ; => "alt: 2" (decase (list :quux 1 2 3)) ; =| error
- Provides
destructuring-case
,destructuring-ccase
,destructuring-ecase
- Requires
- once-only
- extract-function-name v1.0
-
Useful for macros that want to mimic the functional interface for functions like
#'eq
and'eq
.- Provides
extract-function-name
- switch v1.0
-
Dispatch to different branches of code based off of the value of an expression.
- Provides
switch
,eswitch
,cswitch
- Requires
- with-gensyms, extract-function-name
- whichever v1.0
-
Evaluates exactly one of
possibilities
, chosen at random.- Provides
whichever
- Requires
- with-gensyms
- xor v1.0
-
Evaluates its arguments one at a time, from left to right. If more then one argument evaluates to a true value no further
datums
are evaluated, andnil
is returned as both primary and secondary value. If exactly one argument evaluates to true, its value is returned as the primary value after all the arguments have been evaluated, andt
is returned as the secondary value. If no arguments evaluate to truenil
is retuned as primary, andt
as secondary value.- Provides
xor
- Requires
- with-gensyms
- nth-value-or v1.0
-
Evaluates
form
arguments one at a time, until thenth-value
returned by one of the forms is true. It then returns all the values returned by evaluating that form. If none of the forms return a true nth value, this form returnsnil
.- Provides
nth-value-or
- Requires
- with-gensyms, once-only
- multiple-value-prog2 v1.0
-
Evaluates
first-form
, thensecond-form
, and thenforms
. Yields as its value all the value returned bysecond-form
.- Provides
multiple-value-prog2
- featurep v1.0
-
Returns
t
if the argument matches the state of the*features*
list andnil
if it does not.feature-expression
can be any atom or list acceptable to the reader macros#+
and#-
.- Provides
featurep
- Requires
- switch
- ensure-function v1.0
-
Returns the function designated by
function-designator
: iffunction-designator
is a function, it is returned, otherwise it must be a function name and itsfdefinition
is returned.- Provides
ensure-function
- ensure-functionf v1.0
-
Multiple-place modify macro for
ensure-function
: ensures that each ofplaces
contains a function.- Provides
ensure-functionf
- Requires
- ensure-function
- disjoin v1.0
-
Returns a function that applies each of
predicate
andmore-predicate
functions in turn to its arguments, returning the primary value of the first predicate that returns true, without calling the remaining predicates. If none of the predicates returns true,nil
is returned.- Provides
disjoin
- Requires
- ensure-function
- conjoin v1.0
-
Returns a function that applies each of
predicate
andmore-predicate
functions in turn to its arguments, returningnil
if any of the predicates returns false, without calling the remaining predicates. If none of the predicates returns false, returns the primary value of the last predicate.- Provides
conjoin
- compose v1.0
-
Returns a function composed of
function
andmore-functions
that applies its ; arguments to to each in turn, starting from the rightmost ofmore-functions
, and then calling the next one with the primary value of the last.- Provides
compose
- Requires
- make-gensym-list, ensure-function
- multiple-value-compose v1.0
-
Returns a function composed of
function
andmore-functions
that applies its arguments to each in turn, starting from the rightmost ofmore-functions
, and then calling the next one with all the return values of the last.- Provides
multiple-value-compose
- Requires
- make-gensym-list, ensure-function
- curry v1.0
-
Returns a function that applies
arguments
and the arguments it is called with tofunction
.- Provides
curry
- Requires
- make-gensym-list, ensure-function
- rcurry v1.0
-
Returns a function that applies the arguments it is called with and
arguments
tofunction
.- Provides
rcurry
- Requires
- ensure-function
- named-lambda v1.0
-
Expands into a lambda-expression within whose
body
name
denotes the corresponding function.- Provides
named-lambda
- array-bounds v1.0
-
Types related to array bounds.
- Provides
array-index
,array-length
- sub-interval-numeric-types v1.0
-
Contains 'sub-interval numeric types'. Majority of the implementation of CDR5.
- Provides
negative-double-float
,negative-fixnum-p
,negative-float
,negative-float-p
,negative-long-float
,negative-long-float-p
,negative-rational
,negative-rational-p
,negative-real
,negative-single-float-p
,non-negative-double-float
,non-negative-double-float-p
,non-negative-fixnum
,non-negative-fixnum-p
,non-negative-float
,non-negative-float-p
,non-negative-integer-p
,non-negative-long-float
,non-negative-rational
,non-negative-real-p
,non-negative-short-float-p
,non-negative-single-float
,non-negative-single-float-p
,non-positive-double-float
,non-positive-double-float-p
,non-positive-fixnum
,non-positive-fixnum-p
,non-positive-float
,non-positive-float-p
,non-positive-integer
,non-positive-rational
,non-positive-real
,non-positive-real-p
,non-positive-short-float
,non-positive-short-float-p
,non-positive-single-float-p
,positive-double-float
,positive-double-float-p
,positive-fixnum
,positive-fixnum-p
,positive-float
,positive-float-p
,positive-integer
,positive-rational
,positive-real
,positive-real-p
,positive-short-float
,positive-short-float-p
,positive-single-float
,positive-single-float-p
,negative-double-float-p
,negative-fixnum
,negative-integer
,negative-integer-p
,negative-real-p
,negative-short-float
,negative-short-float-p
,negative-single-float
,non-negative-integer
,non-negative-long-float-p
,non-negative-rational-p
,non-negative-real
,non-negative-short-float
,non-positive-integer-p
,non-positive-long-float
,non-positive-long-float-p
,non-positive-rational-p
,non-positive-single-float
,positive-integer-p
,positive-long-float
,positive-long-float-p
,positive-rational-p
- Requires
- format-symbol
- of-type v1.0
-
Returns a function of one argument, which returns true when its argument is of TYPE.
- Provides
of-type
- Requires
- with-gensyms
- type= v1.0
-
Returns a primary value of
t
istype1
andtype2
are the same type, and a secondary value that is true is the type equality could be reliably determined: primary value ofnil
and secondary value oft
indicates that the types are not equivalent.- Provides
type=
- coercef v1.0
-
Modify-macro for
coerce
.- Provides
coercef
- copy-array v1.0
-
Returns an undisplaced copy of
array
, with samefill-pointer
and adjustability (if any) as the original, unless overridden by the keyword arguments.- Provides
copy-array
- alist-plist v1.0
-
Convert between alists and plists.
- Provides
alist-plist
,plist-alist
- Requires
- safe-endp
- assoc-value v1.0
-
Getters and setters for
assoc
andrassoc
values.- Provides
assoc-value
,rassoc-value
- Requires
- with-gensyms
- doplist v1.0
-
Iterates over elements of
plist
.body
can be preceded by declarations, and is like atagbody
.return
may be used to terminate the iteration early. Ifreturn
is not used, returnsvalues
.- Provides
doplist
- Requires
- parse-body, with-gensyms
- appendf v1.0
-
Modify-macro for
append
. Appendslists
to the place designated by the first argument.- Provides
appendf
- nconcf v1.0
-
Modify-macro for
nconc
. Concatenateslists
to place designated by the first argument.- Provides
nconcf
- unionf v1.0
-
Modify-macro for
union
. Saves the union oflist
and the contents of the place designated by the first argument to the designated place.- Provides
unionf
- nunionf v1.0
-
Modify-macro for
nunion
. Saves the union oflist
and the contents of the place designated by the first argument to the designated place. May modify either argument.- Provides
nunionf
- reversef v1.0
-
Modify-macro for
reverse
. Copies and reverses the list stored in the given place and saves back the result into the place.- Provides
reversef
- nreversef v1.0
-
Modify-macro for
nreverse
. Reverses the list stored in the given place by destructively modifying it and saves back the result into the place.- Provides
nreversef
- circular-list v1.0
-
Creation and detection of circular lists.
- Provides
circular-list
,circular-list-p
,make-circular-list
- circular-tree-p v1.0
-
Returns true if
object
is a circular tree,nil
otherwise.- Provides
circular-tree-p
- proper-list-p v1.0
-
Returns true if
object
is a proper list.- Provides
proper-list-p
- proper-list v1.0
-
Type designator for proper lists. Implemented as a
satisfies
type, hence not recommended for performance intensive use. Main usefulness as a type designator of the expected type in atype-error
.- Provides
proper-list
- Requires
- proper-list-p
- proper-list-length/last-car v1.0
-
Compute the length of a proper list, and the last CAR of a list quickly.
- Provides
proper-list-length
,last-car
- Requires
- circular-list, safe-endp
- ensure-car v1.0
-
If
thing
is acons
, itscar
is returned. Otherwisething
is returned.- Provides
ensure-car
- ensure-cons v1.0
-
If
cons
is a cons, it is returned. Otherwise returns a fresh cons withcons
in the car, andnil
in the cdr.- Provides
ensure-cons
- ensure-list v1.0
-
If
list
is a list, it is returned. Otherwise returns the list designated bylist
.- Provides
ensure-list
- remove-from-plist v1.0
-
Destructive and non-destructive functions to remove items from a plist, as well as associated modify macros.
- Provides
remove-from-plist
,delete-from-plist
,remove-from-plistf
,delete-from-plistf
,sans
- mappend v1.0
-
Applies
function
to respective element(s) of eachlist
, appending all the all the result list to a single list.function
must return a list.- Provides
mappend
- setp v1.0
-
Returns true if
object
is a list that denotes a set,nil
otherwise. A list denotes a set if each element of the list is unique underkey
andtest
.- Provides
setp
- set-equal v1.0
-
Returns true if every element of
list1
matches some element oflist2
and every element oflist2
matches some element oflist1
. Otherwise returns false.- Provides
set-equal
- map-product v1.0
-
Returns a list containing the results of calling
function
with one argument fromlist
, and one from each ofmore-lists
for each combination of arguments. In other words, returns the product oflist
andmore-lists
usingfunction
.Example:
(map-product 'list '(1 2) '(3 4) '(5 6)) => ((1 3 5) (1 3 6) (1 4 5) (1 4 6) (2 3 5) (2 3 6) (2 4 5) (2 4 6))
- Provides
map-product
- Requires
- ensure-function, curry, mappend
- with-open-file* v1.0
-
Just like
with-open-file
, butnil
values in the keyword arguments mean to use the default value specified foropen
.- Provides
with-open-file*
- Requires
- once-only
- with-input-from-file v1.0
-
Evaluate
body
withstream-name
to an input stream on the filefile-name
.args
is sent as is to the call toopen
exceptexternal-format
, which is only sent towith-open-file
when it's notnil
.- Provides
with-input-from-file
- Requires
- with-open-file*
- with-output-to-file v1.0
-
Evaluate
body
withstream-name
to an output stream on the filefile-name
.args
is sent as is to the call toopen
exceptexternal-format
, which is only sent towith-open-file
when it's notnil
.- Provides
with-output-to-file
- Requires
- with-open-file*
- read-file-into-string v1.0
-
Return the contents of the file denoted by
pathname
as a fresh string.The
external-format
parameter will be passed directly towith-open-file
unless it'snil
, which means the system default.- Provides
read-file-into-string
- Requires
- with-input-from-file
- write-string-into-file v1.0
-
Write
string
topathname
.The
external-format
parameter will be passed directly towith-open-file
unless it'snil
, which means the system default.- Provides
write-string-into-file
- Requires
- with-output-to-file
- read-file-into-byte-vector v1.0
-
Read
pathname
into a freshly allocated(unsigned-byte 8)
vector.- Provides
read-file-into-byte-vector
- Requires
- with-input-from-file
- write-byte-vector-into-file v1.0
-
Write
bytes
topathname
.- Provides
write-byte-vector-into-file
- Requires
- with-output-to-file
- copy-file v1.0
-
Copy a file from
from
toto
.- Provides
copy-file
- Requires
- copy-stream, with-output-to-file, with-input-from-file
- copy-stream v1.0
-
Reads data from
input
and writes it tooutput
. Bothinput
andoutput
must be streams, they will be passed toread-sequence
andwrite-sequence
and must have compatibleelement-type
s.- Provides
copy-stream
- Requires
- sub-interval-numeric-types
- sequence-of-length-p v1.0
-
- Provides
sequence-of-length-p
- Requires
- array-bounds
- rotate v1.0
-
Returns a sequence of the same type as
sequence
, with the elements ofsequence
rotated byn
:n
elements are moved from the end of the sequence to the front ifn
is positive, and-n
elements moved from the front to the end ifn
is negative.sequence
must be a proper sequence.n
must be an integer, defaulting to1
.If absolute value of
n
is greater then the length of the sequence, the results are identical to callingrotate
with(* (signum n) (mod n (length sequence))).
Note: the original sequence may be destructively altered, and result sequence may share structure with it.
- Provides
rotate
- Requires
- proper-list-length/last-car
- shuffle v1.0
-
Returns a random permutation of
sequence
bounded bystart
andend
. Original sequece may be destructively modified, and share storage with the original one. Signals an error ifsequence
is not a proper sequence.- Provides
shuffle
- Requires
- proper-list-length/last-car
- random-elt v1.0
-
Returns a random element from
sequence
bounded bystart
andend
. Signals an error if thesequence
is not a proper non-empty sequence, or ifend
andstart
are not proper bounding index designators forsequence
.- Provides
random-elt
- Requires
- proper-list-length/last-car
- removef v1.0
-
Modify-macro for
remove
. Sets place designated by the first argument to the result of callingremove
withitem
, place, and thekeyword-arguments
.- Provides
removef
- deletef v1.0
-
Modify-macro for
delete
. Sets place designated by the first argument to the result of callingdelete
withitem
, place, and thekeyword-arguments
.- Provides
deletef
- proper-sequence v1.0
-
Type designator for proper sequences, that is proper lists and sequences that are not lists.
- Provides
proper-sequence
- Requires
- proper-list
- length= v1.0
-
Takes any number of sequences or integers in any order. Returns true iff the length of all the sequences and the integers are equal.
Hint: there's a compiler macro that expands into more efficient code if the first argument is a literal integer.
- Provides
length=
- Requires
- with-gensyms, sequence-of-length-p, array-bounds
- copy-sequence v1.0
-
Returns a fresh sequence of
type
, which has the same elements assequence
.- Provides
copy-sequence
- first-elt v1.0
-
Getter and setter for the first element of a sequence.
- Provides
first-elt
- Requires
- emptyp
- last-elt v1.0
-
Getter and setter for the last element of a sequence.
- Provides
last-elt
- Requires
- proper-list-length/last-car, emptyp, proper-sequence
- starts-with-subseq v1.0
-
Test whether the first elements of SEQUENCE are the same (as per TEST) as the elements of PREFIX.
If RETURN-SUFFIX is T the functions returns, as a second value, a displaced array pointing to the sequence after PREFIX.
- Provides
starts-with-subseq
- Requires
- remove-from-plist
- ends-with-subseq v1.0
-
Test whether
sequence
ends withsuffix
. In other words: return true if the last(length suffix
) elements ofsequence
are equal tosuffix
.- Provides
ends-with-subseq
- starts-with v1.0
-
Returns true if
sequence
is a sequence whose first element iseql
toobject
. Returnsnil
if thesequence
is not a sequence or is an empty sequence.- Provides
starts-with
- ends-with v1.0
-
Returns true if
sequence
is a sequence whose last element iseql
toobject
. Returnsnil
if thesequence
is not a sequence or is an empty sequence. Signals an error ifsequence
is an improper list.- Provides
ends-with
- Requires
- proper-list-length/last-car
- map-combinations v1.0
-
Calls
function
with each combination oflength
constructable from the elements of the subsequence ofsequence
delimited bystart
andend
.start
defaults to0
,end
to length ofsequence
, andlength
to the length of the delimited subsequence. (So unlesslength
is specified there is only a single combination, which has the same elements as the delimited subsequence.) Ifcopy
is true (the default) each combination is freshly allocated. Ifcopy
is false all combinations areeq
to each other, in which case consequences are specified if a combination is modified byfunction
.- Provides
map-combinations
- Requires
- ensure-function
- map-permutations v1.0
-
Calls function with each permutation of
length
constructable from the subsequence ofsequence
delimited bystart
andend
.start
defaults to0
,end
to length of the sequence, andlength
to the length of the delimited subsequence.- Provides
map-permutations
- Requires
- map-combinations
- map-derangements v1.0
-
Calls
function
with each derangement of the subsequence ofsequence
denoted by the bounding index designatorsstart
andend
. Derangement is a permutation of the sequence where no element remains in place.sequence
is not modified, but individual derangements areeq
to each other. Consequences are unspecified if callingfunction
modifies either the derangement orsequence
.- Provides
map-derangements
- extremum v1.0
-
Returns the element of
sequence
that would appear first if the subsequence bounded bystart
andend
was sorted usingpredicate
andkey
.extremum
determines the relationship between two elements ofsequence
by using thepredicate
function.predicate
should return true if and only if the first argument is strictly less than the second one (in some appropriate sense). Two argumentsx
andy
are considered to be equal if(funcall predicate x y)
and(funcall predicate y x)
are both false.The arguments to the
predicate
function are computed from elements ofsequence
using thekey
function, if supplied. Ifkey
is not supplied or isnil
, the sequence element itself is used.If
sequence
is empty,nil
is returned.- Provides
extremum
- Requires
- ensure-function
- clamp v1.0
-
Clamps the
number
into [min
,max
] range. Returnsmin
ifnumber
is lesser thenmin
andmax
ifnumber
is greater thenmax
, otherwise returnsnumber
.- Provides
clamp
- gaussian-random v1.0
-
Returns two gaussian random double floats as the primary and secondary value, optionally constrained by
min
andmax
. Gaussian random numbers form a standard normal distribution around0.0d0
.Sufficiently positive
min
or negativemax
will cause the algorithm used to take a very long time. Ifmin
is positive it should be close to zero, and similarly ifmax
is negative it should be close to zero.- Provides
gaussian-random
- iota v1.0
-
Return a list of
n
numbers, starting fromstart
(with numeric contagion fromstep
applied), each consequtive number being the sum of the previous one andstep
.start
defaults to0
andstep
to1
.Examples:
(iota 4) => (0 1 2 3) (iota 3 :start 1 :step 1.0) => (1.0 2.0 3.0) (iota 3 :start -1 :step -1/2) => (-1 -3/2 -2)
- Provides
iota
- map-iota v1.0
-
Calls
function
withn
numbers, starting fromstart
(with numeric contagion fromstep
applied), each consequtive number being the sum of the previous one andstep
.start
defaults to0
andstep
to1
. Returnsn
.Examples:
(map-iota #'print 3 :start 1 :step 1.0) => 3 ;;; 1.0 ;;; 2.0 ;;; 3.0
- Provides
map-iota
- lerp v1.0
-
Returns the result of linear interpolation between
a
andb
, using the interpolation coefficientv
.- Provides
lerp
- mean v1.0
-
Returns the mean of
sample
.sample
must be a sequence of numbers.- Provides
mean
- median v1.0
-
Returns median of
sample
.sample
must be a sequence of real numbers.- Provides
median
- Requires
- copy-sequence
- variance v1.0
-
Variance of
sample
. Returns the biased variance ifbiased
is true (the default), and the unbiased estimator of variance ifbiased
is false.sample
must be a sequence of numbers.- Provides
variance
- Requires
- mean
- standard-deviation v1.0
-
Standard deviation of
sample
. Returns the biased standard deviation ifbiased
is true (the default), and the square root of the unbiased estimator for variance ifbiased
is false (which is not the same as the unbiased estimator for standard deviation).sample
must be a sequence of numbers.- Provides
standard-deviation
- Requires
- variance
- maxf v1.0
-
Modify-macro for
max
. Sets place designated by the first argument to the maximum of its original value andnumbers
.- Provides
maxf
- minf v1.0
-
Modify-macro for
min
. Sets place designated by the first argument to the minimum of its original value andnumbers
.- Provides
minf
- subfactorial v1.0
-
Subfactorial of the non-negative integer
n
.- Provides
subfactorial
- count-permutations v1.0
-
Number of
k
element permutations for a sequence ofn
objects.k
defaults ton
- Provides
count-permutations
- Requires
- range-product