Alexandria software and associated documentation are in the public domain:
Authors dedicate this work to public domain, for the benefit of the public at large and to the detriment of the authors' heirs and successors. Authors intends this dedication to be an overt act of relinquishment in perpetuity of all present and future rights under copyright law, whether vested or contingent, in the work. Authors understands that such relinquishment of all rights includes the relinquishment of all rights to enforce (by lawsuit or otherwise) those copyrights in the work.Authors recognize that, once placed in the public domain, the work may be freely reproduced, distributed, transmitted, used, modified, built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or conceived.
In those legislations where public domain dedications are not recognized or possible, Alexandria is distributed under the following terms and conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Like
gethash, but ifkeyis not found in thehash-tablesaves thedefaultunder key before returning it. Secondary return value is true if key was already in the table.
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,
keyis invoked on the value. Askeydefaults tocl:identity, a shallow copy is returned by default.
Like
maphash, but callsfunctionwith each key in the hash tabletable.
Like
maphash, but callsfunctionwith each value in the hash tabletable.
Returns an association list containing the keys and values of hash table
table.
Returns a property list containing the keys and values of hash table
table.
Returns a hash table containing the keys and values of the association list
alist. Hash table is initialized using thehash-table-initargs.
Returns a hash table containing the keys and values of the property list
plist. Hash table is initialized using thehash-table-initargs.
Ensures that the global variable named by
nameis a constant with a value that is equal undertestto the result of evaluatinginitial-value.testis a /function designator/ that defaults toeql. Ifdocumentationis given, it becomes the documentation string of the constant.Signals an error if
nameis already a bound non-constant variable.Signals an error if
nameis already a constant variable whose value is not equal undertestto result of evaluatinginitial-value.
destructuring-case,-ccase, and-ecaseare a combination ofcaseanddestructuring-bind.keyformmust evaluate to acons.Clauses are of the form:
((CASE-KEYS . DESTRUCTURING-LAMBDA-LIST) FORM*)The clause whose
case-keysmatchescarofkey, as if bycase,ccase, orecase, is selected, and FORMs are then executed withcdrofkeyis 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
Multiple-place modify macro for
ensure-function:ensures that each ofplacescontains a function.
Evaluates
first-form, thensecond-form, and thenforms. Yields as its value all the value returned bysecond-form.
Expands into a lambda-expression within whose
bodynamedenotes the corresponding function.
Evaluates
formarguments one at a time, until thenth-valuereturned 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.
Creates new variable bindings, and conditionally executes either
then-formorelse-form.else-formdefaults tonil.
bindingsmust 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-formis executed with the bindings in effect, otherwise theelse-formis executed with the bindings in effect.
Creates new variable bindings, and conditionally executes
forms.
bindingsmust 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, then
formsare executed as an implicitprogn.
Creates new variable bindings, and conditionally executes
forms.
bindingsmust 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))Each initial-form is executed in turn, and the variable bound to the corresponding value. Initial-form expressions can refer to variables previously bound by the
when-let*.Execution of
when-let*stops immediately if any initial-form evaluates tonil. If all initial-forms evaluate to true, thenformsare executed as an implicitprogn.
Evaluates first matching clause, returning its values, or evaluates and returns the values of
defaultif no keys match.
Like
switch, but signals a continuable error if no key matches.
Evaluates its arguments one at a time, from left to right. If more then one argument evaluates to a true value no further
datumsare evaluated, andnilis 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, andtis returned as the secondary value. If no arguments evaluate to truenilis retuned as primary, andtas secondary value.
Returns a function that applies each of
predicateandmore-predicatefunctions 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,nilis returned.
Returns a function that applies each of
predicateandmore-predicatefunctions in turn to its arguments, returningnilif 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.
Returns a function composed of
functionandmore-functionsthat 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.
Returns the function designated by
function-designator:iffunction-designatoris a function, it is returned, otherwise it must be a function name and itsfdefinitionis returned.
Returns a function composed of
functionandmore-functionsthat 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.
Returns a function that applies
argumentsand the arguments it is called with tofunction.
Returns a function that applies the arguments it is called with and
argumentstofunction.
Type designator for proper lists. Implemented as a
satisfiestype, hence not recommended for performance intensive use. Main usefullness as a type designator of the expected type in atype-error.
Type designator for circular lists. Implemented as a
satisfiestype, so not recommended for performance intensive use. Main usefullness as the expected-type designator of atype-error.
Modify-macro for
append. Appendsliststo the place designated by the first argument.
Modify-macro for
nconc. Concatenatesliststo place designated by the first argument.
Modify-macro for
reverse. Copies and reverses the list stored in the given place and saves back the result into the place.
Modify-macro for
nreverse. Reverses the list stored in the given place by destructively modifying it and saves back the result into the place.
Modify-macro for
union. Saves the union oflistand the contents of the place designated by the first argument to the designated place.
Modify-macro for
nunion. Saves the union oflistand the contents of the place designated by the first argument to the designated place. May modify either argument.
Iterates over elements of
plist.bodycan be preceded by declarations, and is like atagbody.returnmay be used to terminate the iteration early. Ifreturnis not used, returnsvalues.
Returns a property list containing the same keys and values as the association list
alistin the same order.
Returns an association list containing the same keys and values as the property list
plistin the same order.
Creates a circular list of
lengthwith the giveninitial-element.
If
consis a cons, it is returned. Otherwise returns a fresh cons withconsin the car, andnilin the cdr.
If
listis a list, it is returned. Otherwise returns the list designated bylist.
Returns the last element of
list. Signals a type-error iflistis not a proper list.
Sets the last element of
list. Signals a type-error iflistis not a proper list.
Returns length of
list, signalling an error if it is not a proper list.
Applies
functionto respective element(s) of eachlist, appending all the all the result list to a single list.functionmust return a list.
Returns a list containing the results of calling
functionwith one argument fromlist, and one from each ofmore-listsfor each combination of arguments. In other words, returns the product oflistandmore-listsusingfunction.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))
Returns a propery-list with same keys and values as
plist, except that keys in the list designated bykeysand values corresponding to them are removed. The returned property-list may share structure with theplist, butplistis not destructively modified. Keys are compared usingeq.
Just like
remove-from-plist, but this version may destructively modify the provided plist.
Returns true if every element of
list1matches some element oflist2and every element oflist2matches some element oflist1. Otherwise returns false.
Returns true if
objectis a list that denotes a set,nilotherwise. A list denotes a set if each element of the list is unique underkeyandtest.
Type designator for proper sequences, that is proper lists and sequences that are not lists.
Modify-macro for
delete. Sets place designated by the first argument to the result of callingdeletewithitem, place, and theremove-keywords.
Modify-macro for
remove. Sets place designated by the first argument to the result of callingremovewithitem, place, and theremove-keywords.
Returns a sequence of the same type as
sequence, with the elements ofsequencerotated byn:nelements are moved from the end of the sequence to the front ifnis positive, and-nelements moved from the front to the end ifnis negative.sequencemust be a proper sequence.nmust be an integer, defaulting to1.If absolute value of
nis greater then the length of the sequence, the results are identical to callingrotatewith(* (signum n) (mod n (length sequence))).Note: the original sequence may be destructively altered, and result sequence may share structure with it.
Returns a random permutation of
sequencebounded bystartandend. Original sequece may be destructively modified, and share storage with the original one. Signals an error ifsequenceis not a proper sequence.
Returns a random element from
sequencebounded bystartandend. Signals an error if thesequenceis not a proper non-empty sequence, or ifendandstartare not proper bounding index designators forsequence.
Returns true if
sequenceis an empty sequence. Signals an error ifsequenceis not a sequence.
Return true if
sequenceis a sequence of lengthlength. Signals an error ifsequenceis not a sequence. Returnsfalsefor circular lists.
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.
Returns a fresh sequence of
type, which has the same elements assequence.
Returns the first element of
sequence. Signals a type-error ifsequenceis not a sequence, or is an empty sequence.
Sets the first element of
sequence. Signals a type-error ifsequenceis not a sequence, is an empty sequence, or ifobjectcannot be stored insequence.
Returns the last element of
sequence. Signals a type-error ifsequenceis not a proper sequence, or is an empty sequence.
Sets the last element of
sequence. Signals a type-error ifsequenceis not a proper sequence, is an empty sequence, or ifobjectcannot be stored insequence.
Returns true if
sequenceis a sequence whose first element iseqltoobject. Returnsnilif thesequenceis not a sequence or is an empty sequence.
Test whether the first elements of
sequenceare the same (as per TEST) as the elements ofprefix.If
return-suffixistthe functions returns, as a second value, a displaced array pointing to the sequence afterprefix.
Returns true if
sequenceis a sequence whose last element iseqltoobject. Returnsnilif thesequenceis not a sequence or is an empty sequence. Signals an error ifsequenceis an improper list.
Test whether
sequenceends withsuffix. In other words: return true if the last (length SUFFIX) elements ofsequenceare equal tosuffix.
Calls
functionwith each combination oflengthconstructable from the elements of the subsequence ofsequencedelimited bystartandend.startdefaults to0,endto length ofsequence, andlengthto the length of the delimited subsequence. (So unlesslengthis specified there is only a single combination, which has the same elements as the delimited subsequence.) Ifcopyis true (the default) each combination is freshly allocated. Ifcopyis false all combinations areeqto each other, in which case consequences are specified if a combination is modified byfunction.
Calls
functionwith each derangement of the subsequence ofsequencedenoted by the bounding index designatorsstartandend. Derangement is a permutation of the sequence where no element remains in place.sequenceis not modified, but individual derangements areeqto each other. Consequences are unspecified if callingfunctionmodifies either the derangement orsequence.
Calls function with each permutation of
lengthconstructable from the subsequence ofsequencedelimited bystartandend.startdefaults to0,endto length of the sequence, andlengthto the length of the delimited subsequence.
Return the contents of the file denoted by
pathnameas a fresh string.The
external-formatparameter will be passed directly towith-open-fileunless it'snil, which means the system default.
Read
pathnameinto a freshly allocated (unsigned-byte 8) vector.
Evaluates
formswith symbols specified inspecsrebound to temporary variables, ensuring that each initform is evaluated only once.Each of
specsmust either be a symbol naming the variable to be rebound, or of the form:(symbol initform)Bare symbols in
specsare equivalent to(symbol symbol)Example:
(defmacro cons1 (x) (once-only (x) `(cons ,x ,x))) (let ((y 0)) (cons1 (incf y))) => (1 . 1)
Binds each variable named by a symbol in
namesto a unique symbol aroundforms. Each ofnamesmust either be either a symbol, or of the form:(symbol string-designator)Bare symbols appearing in
namesare equivalent to:(symbol symbol)The string-designator is used as the argument to
gensymwhen constructing the unique symbol the named variable will be bound to.
Returns
tif the argument matches the state of the*features*list andnilif it does not.feature-expressioncan be any atom or list acceptable to the reader macros#+and#-.
Parses
bodyinto (values remaining-forms declarations doc-string). Documentation strings are recognized only ifdocumentationis true. Syntax errors in body are signalled andwholeis used in the signal arguments when given.
Parses an ordinary lambda-list, returning as multiple values:
1. Required parameters.
2. Optional parameter specifications, normalized into form:(name init suppliedp)
3. Name of the rest parameter, ornil.
4. Keyword parameter specifications, normalized into form:((keyword-name name) init suppliedp)
5. Boolean indicating&allow-other-keyspresence.
6.&auxparameter specifications, normalized into form(name init).Signals a
program-erroris the lambda-list is malformed.
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
Constructs a string by applying
argumentsto string designatorcontrolas if byformatwithinwith-standard-io-syntax, and then creates a symbol named by that string.If
packageisnil, 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.
If
nameis a non-negative integer, callsgensymusing it. Otherwisenamemust be a string designator, in which case callsgensymusing the designated string as the argument.
Returns a list of
lengthgensyms, each generated as if with a call tomake-gensym, using the second (optional, defaulting to "G") argument.
Concatenate together the names of some strings and symbols, producing a symbol in the current package.
Type designator for an index into array of
length:an integer between0(inclusive) andlength(exclusive).lengthdefaults toarray-dimension-limit.
Type designator for a dimension of an array of
length:an integer between0(inclusive) andlength(inclusive).lengthdefaults toarray-dimension-limit.
Returns an undisplaced copy of
array, with same fill-pointer and adjustability (if any) as the original, unless overridden by the keyword arguments.
A string designator type. A string designator is either a string, a symbol, or a character.
Returns a function of one argument, which returns true when its argument is of
type.
Returns a primary value of
tistype1andtype2are the same type, and a secondary value that is true is the type equality could be reliably determined: primary value ofniland secondary value oftindicates that the types are not equivalent.
Modify-macro for
max. Sets place designated by the first argument to the maximum of its original value andnumbers.
Modify-macro for
min. Sets place designated by the first argument to the minimum of its original value andnumbers.
Binomial coefficient of
nandk, also expressed asnchoosek. This is the number ofkelement combinations givennchoises.nmust be equal to or greater thenk.
Number of
kelement permutations for a sequence ofnobjects.kdefaults ton
Clamps the
numberinto [min, max] range. Returnsminifnumberis lesser thenminandmaxifnumberis greater thenmax, otherwise returnsnumber.
Returns the result of linear interpolation between A and
b, using the interpolation coefficientv.
Returns two gaussian random double floats as the primary and secondary value, optionally constrained by
minandmax. Gaussian random numbers form a standard normal distribution around0.0d0.Sufficiently positive
minor negativemaxwill cause the algorithm used to take a very long time. Ifminis positive it should be close to zero, and similarly ifmaxis negative it should be close to zero.
Return a list of n numbers, starting from
start(with numeric contagion fromstepapplied), each consequtive number being the sum of the previous one andstep.startdefaults to0andstepto1.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)
Calls
functionwithnnumbers, starting fromstart(with numeric contagion fromstepapplied), each consequtive number being the sum of the previous one andstep.startdefaults to0andstepto1. Returnsn.Examples:
(map-iota #'print 3 :start 1 :step 1.0) => 3 ;;; 1.0 ;;; 2.0 ;;; 3.0
Variance of
sample. Returns the biased variance ifbiasedis true (the default), and the unbiased estimator of variance ifbiasedis false.samplemust be a sequence of numbers.
Standard deviation of
sample. Returns the biased standard deviation ifbiasedis true (the default), and the square root of the unbiased estimator for variance ifbiasedis false (which is not the same as the unbiased estimator for standard deviation).samplemust be a sequence of numbers.