Quickutilβ

Lisp utilities on demand

Fork me on GitHub
search

There are 234 utilities.

octet v1.0

A type representing an octet: 8 bits. If a positive integer n is specified, then (octet n) represents 8n bits. This can often be used for optimization in Common Lisp.

Provides
octet
Source Code
 
positivep v1.0

Check if n is positive.

Provides
positivep
Source Code
 
negativep v1.0

Check if n is negative.

Provides
negativep
Source Code
 
non-negative-p v1.0

Check if n is non-negative.

Provides
non-negative-p
Source Code
 
non-positive-p v1.0

Check if n is non-positive.

Provides
non-positive-p
Source Code
 
non-zero-p v1.0

Check if n is non-zero.

Provides
non-zero-p
Source Code
 
digit-count v2.0

Compute the number of digits in the non-negative integer n in base base. By default, the base is 10.

Provides
digit-count
Source Code
 
range-product v1.0

Compute lower * (lower+1) * ... * (upper-1) * upper.

Provides
range-product
Source Code
 
factorial v1.0

Compute the factorial of n, where n! = 1 * 2 * ... * n.

Provides
factorial
Requires
range-product
Source Code
 
binomial-coefficient v1.0

Binomial coefficient of n and k.

Provides
binomial-coefficient
Requires
factorial, range-product
Source Code
 
mulf v1.0

A modifying version of multiplication, similar to incf.

Provides
mulf
Source Code
 
divf v1.0

A modifying version of division, similar to decf.

Provides
divf
Source Code
 
half v1.0

Compute half of x.

Provides
half
Source Code
 
double v1.0

Compute double x.

Provides
double
Source Code
 
square v1.0

Compute the square of x.

Provides
square
Source Code
 
cube v1.0

Compute the cube of x.

Provides
cube
Source Code
 
digits v1.0

Return a list of the digits of the non-negative integer n in base base. By default, decimal digits are returned.

The order of the digits is such that the kth element of the list refers to the coefficient of base^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
Source Code
 
nth-digit v1.0

Get the nth digit in a rational number number in base base. If n 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
Source Code
 
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, unless least-significant-first is true.

Provides
bit-vector-integer
Source Code
 
integer-bit-vector v1.0

Convert a positive integer n to a bit vector. The least significant bits will be first if least-significant-first is true.

Provides
integer-bit-vector
Source Code
 
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
Source Code
 
sec v1.0

Compute the secant of a number z.

Provides
sec
Source Code
 
csc v1.0

Compute the cosecant of a number z.

Provides
csc
Source Code
 
cot v1.0

Compute the cotangent of a number z.

Provides
cot
Source Code
 
asec v1.0

Compute the arcsecant of a number z.

Provides
asec
Source Code
 
acsc v1.0

Compute the arccosecant of a number z.

Provides
acsc
Source Code
 
acot v1.0

Compute the arccotangent of a number z.

Provides
acot
Source Code
 
sort-copy v1.0

Copying versions of cl:sort and cl:stable-sort.

Provides
sort-copystable-sort-copy
Source Code
 
take v1.0

Take the first n elements from sequence.

Provides
take
Source Code
 
drop v1.0

Drop the first n elements from sequence.

Provides
drop
Source Code
 
subdivide v1.0

Split sequence into subsequences of size chunk-size.

Provides
subdivide
Source Code
 
n-grams v1.0

Find all n-grams of the sequence sequence.

Provides
n-grams
Requires
take
Source Code
 
partition-if v1.0

Partition sequences based off of a predicate.

Provides
partition-ifpartition-if-not
Source Code
 
equivalence-classes v1.0

Partition the sequence seq into a list of equivalence classes defined by the equivalence relation equiv.

Provides
equivalence-classes
Source Code
 
doseq v1.0

Iterate across the sequence seq, binding the variable var to each element of the sequence and executing body. Return the value return from the iteration form.

Provides
doseq
Source Code
 
range v1.0

Return the list of numbers n such that start <= n < end and n = start + k*step for suitable integers k. If a function key is provided, then apply it to each number.

Provides
range
Source Code
 
replicate v1.0

Make a list of n copies of x.

Provides
replicate
Source Code
 
slice v1.0

Compute the slice of a list list at indexes indexes.

Provides
slice
Source Code
 
transpose v1.0

Analog to matrix transpose for a list of lists given by lists.

Provides
transpose
Source Code
 
zip v1.0

Take a tuple of lists and turn them into a list of tuples. Equivalent to unzip.

Provides
zip
Requires
transpose
Source Code
 
unzip v1.0

Take a list of tuples and return a tuple of lists. Equivalent to zip.

Provides
unzip
Requires
transpose
Source Code
 
long-zip v1.0

zip using the longest, rather than shortest list, filling with fill.

Provides
long-zip
Requires
zip
Source Code
 
enumerate v1.0

Equivalent to (zip (iota (length list)) list).

Provides
enumerate
Source Code
 
flatten-once v1.0

Flatten list once.

Provides
flatten-once
Source Code
 
flatten-tagged-once v1.0

Flatten once a list x with a tag tag.

Provides
flatten-tagged-once
Source Code
 
flatten v1.0

Flatten (and append) all lists xs completely.

Provides
flatten
Source Code
 
ncycle v1.0

Mutate list into a circlular list.

Provides
ncycle
Source Code
 
cycle v1.0

Make list into a circular list.

Provides
cycle
Requires
ncycle
Source Code
 
nest v1.0

Compute a count compositions of function on initial-value.

Provides
nest
Source Code
 
nest-list v1.0

Compute a list of count compositions of function on initial-value.

Provides
nest-list
Source Code
 
safe-nth v1.0

Find the nth element of list. If n is out of bounds, return if-out-of-bounds (nil by default).

Provides
safe-nth
Source Code
 
mapply v1.0

Apply f to each list of arguments contained within list and collect the results.

Provides
mapply
Source Code
 
cartesian-product v1.0

Compute the cartesian product of l1 and l2 as if they were sets. Optionally, map the function f across the product.

Provides
cartesian-product
Source Code
 
end v1.0

Return the last element of list and whether or not it was empty.

Provides
end
Source Code
 
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
Source Code
 
collect-reduce v1.0

Collects intermediate reduction results of applying f to list. More or less equivalent to (loop :for i :in list :collect (reduce f i)).

Provides
collect-reduce
Source Code
 
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
Source Code
 
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
Source Code
 
riffle v1.0

Insert the item obj in between each element of list.

Provides
riffle
Source Code
 
extend v1.0

Adjoin x to the end of xs.

Provides
extend
Source Code
 
list-to-vector v1.0

Convert list into a vector.

Provides
list-to-vector
Source Code
 
sequence-to-list v1.0

Convert the sequence seq into a list.

Provides
sequence-to-list
Source Code
 
explode v1.0

The classic explode function. Take a string and return a list of its characters.

Provides
explode
Requires
sequence-to-list
Source Code
 
implode v1.0

The classic implode function. Take a list of characters and return the corresponding string.

Provides
implode
Requires
list-to-vector
Source Code
 
inits v1.0

Generate a list of initial sublists of the list list. The name inits 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
Source Code
 
tails v1.0

Generate a list of tails of the list list. The name tails 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
Source Code
 
string-append v1.0

Append strings or a sequence of strings together.

Provides
string-appendstring-append*
Source Code
 
separated-string-append v1.0

Append strings or a sequence of strings, separated by a separator.

Provides
separated-string-appendseparated-string-append*
Source Code
 
string-append-space v1.0

Concatenate strings separated by a single space.

Provides
string-append-space
Requires
separated-string-append
Source Code
 
fix v1.0

Apply the fixed-point combinator, also known as the Y-combinator, to the function F : (A -> B) -> A -> B.

Provides
fix
Source Code
 
flip v1.0

Return a function whose argument order of a binary function f is reversed.

Provides
flip
Source Code
 
applyable v1.0

Given a function fun, return a variadic function which results in fun 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
Source Code
 
applying v1.0

Given a function fun, return a unary function whose result is applying fun to the single argument.

Provides
applying
Source Code
 
compose-apply v1.0

Create a variadic function whose result is applying the function fun to results obtained by applying each of funs 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
Source Code
 
rerank-array v1.0

Reshape array to have dimensions specified by dimensions, possibly with a different rank than the original. The dimensions of array and the given dimensions must have the same total number of elements.

Provides
rerank-array
Source Code
 
vector-range v1.0

Compute the equivalent of (coerce (range a b :step step) 'vector).

Provides
vector-range
Source Code
 
vector-slice v1.0

Compute the slice of a vector v at indexes indexes.

Provides
vector-slice
Source Code
 
vector-associative-reduce v1.0

Reduce vector with associative-function, using a divide-and-conquer method.

Provides
vector-associative-reduce
Source Code
 
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 of make-array.

Provides
array-contents
Source Code
 
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
Source Code
 
map-tree v1.0

Map function to each of the leave of tree.

Provides
map-tree
Source Code
 
tree-member-p v1.0

Returns t if item is in tree, nil otherwise.

Provides
tree-member-p
Source Code
 
tree-collect v1.0

Returns a list of every node in the tree that satisfies the predicate. If there are any improper lists in the tree, the predicate is also applied to their dotted elements.

Provides
tree-collect
Source Code
 
same-name v1.0

Do symbols a and b have the same name?

Provides
same-name
Source Code
 
ensure-keyword v1.0

Ensure that a keyword is returned for the string designator x.

Provides
ensure-keyword
Source Code
 
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
Source Code
 
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
Source Code
 
void v1.0

Do absolutely nothing, and return absolutely nothing.

Provides
void
Source Code
 
ensure-boolean v1.0

Convert x into a Boolean value.

Provides
ensure-boolean
Source Code
 
letf* v1.0

Given a list of bindings whose keys are places and whose values are forms, set them for the duration of body, but restore their values (as visible upon evaluation of this macro) upon completion. The restoration is ensured with unwind-protect.

Provides
letf*
Requires
zip, appendf
Source Code
 
let1 v1.0

Bind VAR to VAL within BODY. Equivalent to LET with one binding.

Provides
let1
Source Code
 
defaccessor v1.0

Define the function named name just as with a normal defun. Also define the setter (setf name). The form to be set (i.e., the place) should be wrapped in the local macro accesses. 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
defaccessoraccesses
Requires
with-gensyms, parse-body
Source Code
 
imaginary-i v1.0

The imaginary number i = sqrt(-1).

Provides
imaginary-iii
Source Code
 
exponential-e v1.0

The exponential number e = 2.71828....

Provides
exponential-eee
Source Code
 
until v1.0

Executes body until expression is true.

Provides
until
Source Code
 
while v1.0

Executes body while expression is true.

Provides
while
Requires
until
Source Code
 
alist-to-hash-table v1.0

Create a hash table populated with kv-pairs.

Provides
alist-to-hash-table
Source Code
 
hash-table-key-exists-p v1.0

Does key exist in hash-table?

Provides
hash-table-key-exists-p
Source Code
 
dohash v1.0

Iterate over the hash table table, executing body, with key and value bound to the keys and values of the hash table respectively. Return result from the iteration form.

Provides
dohash
Source Code
 
reseed-random-state v1.0

Reseed the random state use by the random number generator.

Provides
reseed-random-state
Source Code
 
random-between v1.0

Generate a random integer between a and b, inclusive.

Provides
random-between
Source Code
 
emptyp v1.0

Determine if object is empty.

Provides
emptyp
Requires
non-zero-p
Source Code
 
singletonp v1.0

Determine if object is a singleton object.

Provides
singletonp
Source Code
 
recons v1.0

Reuse the cons cell old-cons, replacing its CAR with a and CDR with b.

Provides
recons
Source Code
 
copy-cons v1.0

Copy the cons cell c.

Provides
copy-cons
Source Code
 
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 arguments args. See CLHS 9.1.2.1 for more specifics.

default-type is the type of objects that should be constructed when datum 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
Source Code
 
true-false v1.0

true and false synonyms for t and nil.

Provides
truefalse
Source Code
 
yes-no v1.0

Always return t or nil. Equivalent to (constantly t) and (constantly nil).

Provides
yesno
Source Code
 
stream-direction v1.0

Return the direction of the stream stream: :input, :output, or :io.

Provides
stream-direction
Source Code
 
make-null-stream v1.0

Null input and output stream constructors.

Provides
make-null-input-streammake-null-output-streammake-null-stream
Source Code
 
matching-null-stream v1.0

Return a null stream whose direction matches stream.

Provides
matching-null-stream
Requires
make-null-stream, stream-direction
Source Code
 
with-ignored-streams v1.0

Ignore any input or output to any of the streams denoted by the symbols streams in the code body.

Provides
with-ignored-streams
Requires
matching-null-stream
Source Code
 
quietly v1.0

Quietly execute body, suppressing all output.

Provides
quietly
Requires
with-ignored-streams
io
Source Code
 
skip-if v1.0

Given a character predicate char-predicate, read past all of the characters of the character stream stream which satisfy that predicate. Optional arguments eof-error-p, eof-value, and recursive-p are the same as in read-char.

Provides
skip-if
Source Code
 
skip v1.0

Read past all of the characters matching char in the character stream stream. Optional arguments eof-error-p, eof-value, and recursive-p are the same as in read-char.

Provides
skip
Requires
skip-if
Source Code
 
syntax-bind v1.0

Set *readtable* to a copy of readtable-expression and modify the copy. Because cl:load and cl:compile-file bind *readtable*, this effectively gives a file local readtable in the same way cl: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 null readtable-expression creates a readtable with standard Common Lisp syntax then applies the character bindings.

Provides
syntax-bind
Source Code
 
split-sequence v1.0

Split sequences into a list of subsequences based off of a delimiter or function.

Provides
split-sequencesplit-sequence-ifsplit-sequence-if-not
Source Code
 
define-constant v1.0

Ensures that the global variable named by name is a constant with a value that is equal under test to the result of evaluating initial-value. test is a function designator that defaults to eql. If documentation 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 under test to result of evaluating initial-value.

Provides
define-constant
Source Code
 
if-let v1.0

Creates new variable bindings, and conditionally executes either then-form or else-form. else-form defaults to nil.

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 the else-form is executed with the bindings in effect.

Provides
if-let
Source Code
 
when-let v1.0

Creates new variable bindings, and conditionally executes a series of forms.

Provides
when-letwhen-let*
Source Code
 
string-designator v1.0

A string designator type. A string designator is either a string, a symbol, or a character.

Provides
string-designator
Source Code
 
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
Source Code
 
simple-style-warning v1.0
Provides
simple-style-warning
Source Code
 
simple-reader-error v1.0
Provides
simple-reader-error
Source Code
 
simple-parse-error v1.0
Provides
simple-parse-error
Source Code
 
simple-program-error v1.0
Provides
simple-program-error
Source Code
 
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
Source Code
 
unwind-protect-case v1.0

Like cl:unwind-protect, but you can specify the circumstances that the cleanup clauses 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 to t in clauses if the protected-form aborted preemptively, and to nil 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
Source Code
 
copy-hash-table v1.0

Returns a copy of hash table table, with the same keys and values as the table. 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. As key defaults to cl:identity, a shallow copy is returned by default.

Provides
copy-hash-table
Source Code
 
maphash-keys v1.0

Like maphash, but calls function with each key in the hash table table.

Provides
maphash-keys
Source Code
 
maphash-values v1.0

Like maphash, but calls function with each value in the hash table table.

Provides
maphash-values
Source Code
 
hash-table-keys v1.0

Returns a list containing the keys of hash table table.

Provides
hash-table-keys
Requires
maphash-keys
Source Code
 
hash-table-values v1.0

Returns a list containing the values of hash table table.

Provides
hash-table-values
Requires
maphash-values
Source Code
 
hash-table-alist v1.0

Returns an association list containing the keys and values of hash table table.

Provides
hash-table-alist
Source Code
 
hash-table-plist v1.0

Returns a property list containing the keys and values of hash table table.

Provides
hash-table-plist
Source Code
 
alist-hash-table v1.0

Returns a hash table containing the keys and values of the association list alist. Hash table is initialized using the hash-table-initargs.

Provides
alist-hash-table
Source Code
 
plist-hash-table v1.0

Returns a hash table containing the keys and values of the property list plist. Hash table is initialized using the hash-table-initargs.

Provides
plist-hash-table
Source Code
 
ensure-gethash v1.0

Like gethash, but if key is not found in the hash-table saves the default under key before returning it. Secondary return value is true if key was already in the table.

Provides
ensure-gethash
Source Code
 
ensure-symbol v1.0

Returns a symbol with name designated by name, accessible in package designated by package. If symbol is not already accessible in package, it is interned there. Returns a secondary value reflecting the status of the symbol in the package, which matches the secondary return value of intern.

Example:

(ensure-symbol :cons :cl) => cl:cons, :external

Provides
ensure-symbol
Source Code
 
format-symbol v1.0

Constructs a string by applying arguments to string designator control as if by format within with-standard-io-syntax, and then creates a symbol named by that string.

If package is nil, returns an uninterned symbol, if package is t, returns a symbol interned in the current package, and otherwise returns a symbol interned in the package designated by package.

Provides
format-symbol
Source Code
 
make-keyword v1.0

Interns the string designated by name in the keyword package.

Provides
make-keyword
Source Code
 
make-gensym v1.0

If name is a non-negative integer, calls gensym using it. Otherwise name must be a string designator, in which case calls gensym using the designated string as the argument.

Provides
make-gensym
Source Code
 
make-gensym-list v1.0

Returns a list of length gensyms, each generated as if with a call to make-gensym, using the second (optional, defaulting to "G") argument.

Provides
make-gensym-list
Source Code
 
symbolicate v1.0

Concatenate together the names of some strings and symbols, producing a symbol in the current package.

Provides
symbolicate
Source Code
 
with-gensyms v1.0

Binds each variable named by a symbol in names to a unique symbol around forms. Each of names 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-gensymswith-unique-names
Requires
string-designator
Source Code
 
once-only v1.0

Evaluates forms with symbols specified in specs 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
Source Code
 
parse-body v1.0

Parses body into (values remaining-forms declarations doc-string). Documentation strings are recognized only if documentation is true. Syntax errors in body are signalled and whole is used in the signal arguments when given.

Provides
parse-body
Source Code
 
parse-ordinary-lambda-list v1.0

Parses an ordinary lambda-list, returning as multiple values:

  1. Required parameters.

  2. Optional parameter specifications, normalized into form:

(name init suppliedp)

  1. Name of the rest parameter, or nil.

  2. Keyword parameter specifications, normalized into form:

((keyword-name name) init suppliedp)

  1. Boolean indicating &allow-other-keys presence.

  2. &aux parameter specifications, normalized into form

(name init).

  1. Existence of &key in the lambda-list.

Signals a program-error if lambda-list is malformed.

Provides
parse-ordinary-lambda-list
Requires
simple-program-error, ensure-list, make-keyword
Source Code
 
destructuring-case v1.0

destructuring-case, 'destructuring-ccase and 'destructuring-ecase are a combination of case and destructuring-bind. keyform must evaluate to af cons.

Clauses are of the form:

((case-keys . destructuring-lambda-list) form*) 

The clause whose case-keys matches car of key, as if by case, ccase, or ecase, is selected, and forms are then executed with cdr of key is destructured and Bound By The destructuring-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-casedestructuring-ccasedestructuring-ecase
Requires
once-only
Source Code
 
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
Source Code
 
switch v1.0

Dispatch to different branches of code based off of the value of an expression.

Provides
switcheswitchcswitch
Requires
with-gensyms, extract-function-name
Source Code
 
whichever v1.0

Evaluates exactly one of possibilities, chosen at random.

Provides
whichever
Requires
with-gensyms
Source Code
 
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, and nil 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, and t is returned as the secondary value. If no arguments evaluate to true nil is retuned as primary, and t as secondary value.

Provides
xor
Requires
with-gensyms
Source Code
 
nth-value-or v1.0

Evaluates form arguments one at a time, until the nth-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 returns nil.

Provides
nth-value-or
Requires
with-gensyms, once-only
Source Code
 
multiple-value-prog2 v1.0

Evaluates first-form, then second-form, and then forms. Yields as its value all the value returned by second-form.

Provides
multiple-value-prog2
Source Code
 
featurep v1.0

Returns t if the argument matches the state of the *features* list and nil if it does not. feature-expression can be any atom or list acceptable to the reader macros #+ and #-.

Provides
featurep
Requires
switch
Source Code
 
ensure-function v1.0

Returns the function designated by function-designator: if function-designator is a function, it is returned, otherwise it must be a function name and its fdefinition is returned.

Provides
ensure-function
Source Code
 
ensure-functionf v1.0

Multiple-place modify macro for ensure-function: ensures that each of places contains a function.

Provides
ensure-functionf
Requires
ensure-function
Source Code
 
disjoin v1.0

Returns a function that applies each of predicate and more-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
Source Code
 
conjoin v1.0

Returns a function that applies each of predicate and more-predicate functions in turn to its arguments, returning nil 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
Source Code
 
compose v1.0

Returns a function composed of function and more-functions that applies its ; arguments to to each in turn, starting from the rightmost of more-functions, and then calling the next one with the primary value of the last.

Provides
compose
Requires
make-gensym-list, ensure-function
Source Code
 
multiple-value-compose v1.0

Returns a function composed of function and more-functions that applies its arguments to each in turn, starting from the rightmost of more-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
Source Code
 
curry v1.0

Returns a function that applies arguments and the arguments it is called with to function.

Provides
curry
Requires
make-gensym-list, ensure-function
Source Code
 
rcurry v1.0

Returns a function that applies the arguments it is called with and arguments to function.

Provides
rcurry
Requires
ensure-function
Source Code
 
named-lambda v1.0

Expands into a lambda-expression within whose body name denotes the corresponding function.

Provides
named-lambda
Source Code
 
array-bounds v1.0

Types related to array bounds.

Provides
array-indexarray-length
Source Code
 
sub-interval-numeric-types v1.0

Contains 'sub-interval numeric types'. Majority of the implementation of CDR5.

Provides
negative-double-floatnegative-fixnum-pnegative-floatnegative-float-pnegative-long-floatnegative-long-float-pnegative-rationalnegative-rational-pnegative-realnegative-single-float-pnon-negative-double-floatnon-negative-double-float-pnon-negative-fixnumnon-negative-fixnum-pnon-negative-floatnon-negative-float-pnon-negative-integer-pnon-negative-long-floatnon-negative-rationalnon-negative-real-pnon-negative-short-float-pnon-negative-single-floatnon-negative-single-float-pnon-positive-double-floatnon-positive-double-float-pnon-positive-fixnumnon-positive-fixnum-pnon-positive-floatnon-positive-float-pnon-positive-integernon-positive-rationalnon-positive-realnon-positive-real-pnon-positive-short-floatnon-positive-short-float-pnon-positive-single-float-ppositive-double-floatpositive-double-float-ppositive-fixnumpositive-fixnum-ppositive-floatpositive-float-ppositive-integerpositive-rationalpositive-realpositive-real-ppositive-short-floatpositive-short-float-ppositive-single-floatpositive-single-float-pnegative-double-float-pnegative-fixnumnegative-integernegative-integer-pnegative-real-pnegative-short-floatnegative-short-float-pnegative-single-floatnon-negative-integernon-negative-long-float-pnon-negative-rational-pnon-negative-realnon-negative-short-floatnon-positive-integer-pnon-positive-long-floatnon-positive-long-float-pnon-positive-rational-pnon-positive-single-floatpositive-integer-ppositive-long-floatpositive-long-float-ppositive-rational-p
Requires
format-symbol
Source Code
 
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
Source Code
 
type= v1.0

Returns a primary value of t is type1 and type2 are the same type, and a secondary value that is true is the type equality could be reliably determined: primary value of nil and secondary value of t indicates that the types are not equivalent.

Provides
type=
Source Code
 
coercef v1.0

Modify-macro for coerce.

Provides
coercef
Source Code
 
copy-array v1.0

Returns an undisplaced copy of array, with same fill-pointer and adjustability (if any) as the original, unless overridden by the keyword arguments.

Provides
copy-array
Source Code
 
alist-plist v1.0

Convert between alists and plists.

Provides
alist-plistplist-alist
Requires
safe-endp
Source Code
 
assoc-value v1.0

Getters and setters for assoc and rassoc values.

Provides
assoc-valuerassoc-value
Requires
with-gensyms
Source Code
 
doplist v1.0

Iterates over elements of plist. body can be preceded by declarations, and is like a tagbody. return may be used to terminate the iteration early. If return is not used, returns values.

Provides
doplist
Requires
parse-body, with-gensyms
Source Code
 
appendf v1.0

Modify-macro for append. Appends lists to the place designated by the first argument.

Provides
appendf
Source Code
 
nconcf v1.0

Modify-macro for nconc. Concatenates lists to place designated by the first argument.

Provides
nconcf
Source Code
 
unionf v1.0

Modify-macro for union. Saves the union of list and the contents of the place designated by the first argument to the designated place.

Provides
unionf
Source Code
 
nunionf v1.0

Modify-macro for nunion. Saves the union of list and the contents of the place designated by the first argument to the designated place. May modify either argument.

Provides
nunionf
Source Code
 
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
Source Code
 
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
Source Code
 
circular-list v1.0

Creation and detection of circular lists.

Provides
circular-listcircular-list-pmake-circular-list
Source Code
 
circular-tree-p v1.0

Returns true if object is a circular tree, nil otherwise.

Provides
circular-tree-p
Source Code
 
proper-list-p v1.0

Returns true if object is a proper list.

Provides
proper-list-p
Source Code
 
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 a type-error.

Provides
proper-list
Requires
proper-list-p
Source Code
 
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-lengthlast-car
Requires
circular-list, safe-endp
Source Code
 
ensure-car v1.0

If thing is a cons, its car is returned. Otherwise thing is returned.

Provides
ensure-car
Source Code
 
ensure-cons v1.0

If cons is a cons, it is returned. Otherwise returns a fresh cons with cons in the car, and nil in the cdr.

Provides
ensure-cons
Source Code
 
ensure-list v1.0

If list is a list, it is returned. Otherwise returns the list designated by list.

Provides
ensure-list
Source Code
 
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-plistdelete-from-plistremove-from-plistfdelete-from-plistfsans
Source Code
 
mappend v1.0

Applies function to respective element(s) of each list, appending all the all the result list to a single list. function must return a list.

Provides
mappend
Source Code
 
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 under key and test.

Provides
setp
Source Code
 
set-equal v1.0

Returns true if every element of list1 matches some element of list2 and every element of list2 matches some element of list1. Otherwise returns false.

Provides
set-equal
Source Code
 
map-product v1.0

Returns a list containing the results of calling function with one argument from list, and one from each of more-lists for each combination of arguments. In other words, returns the product of list and more-lists using function.

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
Source Code
 
with-open-file* v1.0

Just like with-open-file, but nil values in the keyword arguments mean to use the default value specified for open.

Provides
with-open-file*
Requires
once-only
Source Code
 
with-input-from-file v1.0

Evaluate body with stream-name to an input stream on the file file-name. args is sent as is to the call to open except external-format, which is only sent to with-open-file when it's not nil.

Provides
with-input-from-file
Requires
with-open-file*
Source Code
 
with-output-to-file v1.0

Evaluate body with stream-name to an output stream on the file file-name. args is sent as is to the call to open except external-format, which is only sent to with-open-file when it's not nil.

Provides
with-output-to-file
Requires
with-open-file*
Source Code
 
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 to with-open-file unless it's nil, which means the system default.

Provides
read-file-into-string
Requires
with-input-from-file
Source Code
 
write-string-into-file v1.0

Write string to pathname.

The external-format parameter will be passed directly to with-open-file unless it's nil, which means the system default.

Provides
write-string-into-file
Requires
with-output-to-file
Source Code
 
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
Source Code
 
write-byte-vector-into-file v1.0

Write bytes to pathname.

Provides
write-byte-vector-into-file
Requires
with-output-to-file
Source Code
 
copy-file v1.0

Copy a file from from to to.

Provides
copy-file
Requires
copy-stream, with-output-to-file, with-input-from-file
Source Code
 
copy-stream v1.0

Reads data from input and writes it to output. Both input and output must be streams, they will be passed to read-sequence and write-sequence and must have compatible element-types.

Provides
copy-stream
Requires
sub-interval-numeric-types
Source Code
 
sequence-of-length-p v1.0
Provides
sequence-of-length-p
Requires
array-bounds
Source Code
 
rotate v1.0

Returns a sequence of the same type as sequence, with the elements of sequence rotated by n: n elements are moved from the end of the sequence to the front if n is positive, and -n elements moved from the front to the end if n is negative. sequence must be a proper sequence. n must be an integer, defaulting to 1.

If absolute value of n is greater then the length of the sequence, the results are identical to calling rotate 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
Source Code
 
shuffle v1.0

Returns a random permutation of sequence bounded by start and end. Original sequece may be destructively modified, and share storage with the original one. Signals an error if sequence is not a proper sequence.

Provides
shuffle
Requires
proper-list-length/last-car
Source Code
 
random-elt v1.0

Returns a random element from sequence bounded by start and end. Signals an error if the sequence is not a proper non-empty sequence, or if end and start are not proper bounding index designators for sequence.

Provides
random-elt
Requires
proper-list-length/last-car
Source Code
 
removef v1.0

Modify-macro for remove. Sets place designated by the first argument to the result of calling remove with item, place, and the keyword-arguments.

Provides
removef
Source Code
 
deletef v1.0

Modify-macro for delete. Sets place designated by the first argument to the result of calling delete with item, place, and the keyword-arguments.

Provides
deletef
Source Code
 
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
Source Code
 
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
Source Code
 
copy-sequence v1.0

Returns a fresh sequence of type, which has the same elements as sequence.

Provides
copy-sequence
Source Code
 
first-elt v1.0

Getter and setter for the first element of a sequence.

Provides
first-elt
Requires
emptyp
Source Code
 
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
Source Code
 
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
Source Code
 
ends-with-subseq v1.0

Test whether sequence ends with suffix. In other words: return true if the last (length suffix) elements of sequence are equal to suffix.

Provides
ends-with-subseq
Source Code
 
starts-with v1.0

Returns true if sequence is a sequence whose first element is eql to object. Returns nil if the sequence is not a sequence or is an empty sequence.

Provides
starts-with
Source Code
 
ends-with v1.0

Returns true if sequence is a sequence whose last element is eql to object. Returns nil if the sequence is not a sequence or is an empty sequence. Signals an error if sequence is an improper list.

Provides
ends-with
Requires
proper-list-length/last-car
Source Code
 
map-combinations v1.0

Calls function with each combination of length constructable from the elements of the subsequence of sequence delimited by start and end. start defaults to 0, end to length of sequence, and length to the length of the delimited subsequence. (So unless length is specified there is only a single combination, which has the same elements as the delimited subsequence.) If copy is true (the default) each combination is freshly allocated. If copy is false all combinations are eq to each other, in which case consequences are specified if a combination is modified by function.

Provides
map-combinations
Requires
ensure-function
Source Code
 
map-permutations v1.0

Calls function with each permutation of length constructable from the subsequence of sequence delimited by start and end. start defaults to 0, end to length of the sequence, and length to the length of the delimited subsequence.

Provides
map-permutations
Requires
map-combinations
Source Code
 
map-derangements v1.0

Calls function with each derangement of the subsequence of sequence denoted by the bounding index designators start and end. Derangement is a permutation of the sequence where no element remains in place. sequence is not modified, but individual derangements are eq to each other. Consequences are unspecified if calling function modifies either the derangement or sequence.

Provides
map-derangements
Source Code
 
extremum v1.0

Returns the element of sequence that would appear first if the subsequence bounded by start and end was sorted using predicate and key.

extremum determines the relationship between two elements of sequence by using the predicate function. predicate should return true if and only if the first argument is strictly less than the second one (in some appropriate sense). Two arguments x and y 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 of sequence using the key function, if supplied. If key is not supplied or is nil, the sequence element itself is used.

If sequence is empty, nil is returned.

Provides
extremum
Requires
ensure-function
Source Code
 
clamp v1.0

Clamps the number into [min, max] range. Returns min if number is lesser then min and max if number is greater then max, otherwise returns number.

Provides
clamp
Source Code
 
gaussian-random v1.0

Returns two gaussian random double floats as the primary and secondary value, optionally constrained by min and max. Gaussian random numbers form a standard normal distribution around 0.0d0.

Sufficiently positive min or negative max will cause the algorithm used to take a very long time. If min is positive it should be close to zero, and similarly if max is negative it should be close to zero.

Provides
gaussian-random
Source Code
 
iota v1.0

Return a list of n numbers, starting from start (with numeric contagion from step applied), each consequtive number being the sum of the previous one and step. start defaults to 0 and step to 1.

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
Source Code
 
map-iota v1.0

Calls function with n numbers, starting from start (with numeric contagion from step applied), each consequtive number being the sum of the previous one and step. start defaults to 0 and step to 1. Returns n.

Examples:

(map-iota #'print 3 :start 1 :step 1.0) => 3  
  ;;; 1.0  
  ;;; 2.0  
  ;;; 3.0 
Provides
map-iota
Source Code
 
lerp v1.0

Returns the result of linear interpolation between a and b, using the interpolation coefficient v.

Provides
lerp
Source Code
 
mean v1.0

Returns the mean of sample. sample must be a sequence of numbers.

Provides
mean
Source Code
 
median v1.0

Returns median of sample. sample must be a sequence of real numbers.

Provides
median
Requires
copy-sequence
Source Code
 
variance v1.0

Variance of sample. Returns the biased variance if biased is true (the default), and the unbiased estimator of variance if biased is false. sample must be a sequence of numbers.

Provides
variance
Requires
mean
Source Code
 
standard-deviation v1.0

Standard deviation of sample. Returns the biased standard deviation if biased is true (the default), and the square root of the unbiased estimator for variance if biased 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
Source Code
 
maxf v1.0

Modify-macro for max. Sets place designated by the first argument to the maximum of its original value and numbers.

Provides
maxf
Source Code
 
minf v1.0

Modify-macro for min. Sets place designated by the first argument to the minimum of its original value and numbers.

Provides
minf
Source Code
 
subfactorial v1.0

Subfactorial of the non-negative integer n.

Provides
subfactorial
Source Code
 
count-permutations v1.0

Number of k element permutations for a sequence of n objects. k defaults to n

Provides
count-permutations
Requires
range-product
Source Code