This package contains generally useful utility functions. Several of those functions were taken from (Graham 1996), the SANS function was contributed to the comp.lang.lisp newsgroup by Erik Naggum.
Make the property list supplied in items into a blackboard. Copies items to make sure that no literal list is modified.
A blackboard where data items can be put and extracted using the function
GETBB.Direct slots:
- ITEMS: A property list of items on the blackboard.
This is a dictionary which can only hold a certain number of items. If more are inserted, only the most recently accessed items are kept.
Direct slots:
- SIZE: Self-explanatory.
- TEST: Self-explanatory.
- STORE: Self-explanatory.
- ITEM-STORE: Self-explanatory.
Checks if all of the properties are in the property list place.
Returns the speed which should be characteristic for the setting determined by the keyword arguments.
Returns a uniform constant vector of which all elements are value.
Initializes the slots named in slots from obj2 to obj1. Returns obj1.
Pops an object from queue. Returns as second value T if the queue was empty.
Loops through hash-table. If looping-var is an atom key, loop through the keys; if it is a list of the form (value) loop through the values; if it is a list of the form (key value) loop through key and value.
Generic evaluation of functions on an argument. Numbers and arrays are treated as constants. Special evaluation is defined for multivariate polynomials on vectors and for <function> objects.
Compute the factorial of n. n can also be a list of numbers in which case the product of the factorials of the components is computed.
If the manual is sorted by file, the string handed to this function describes the use of the respective file.
The positive REMOVE - i.e. like REMOVE with :test instead of :test-not.
Calls func on each tuple greater or equal to (0 ... 0) and below dims.
Gets property for object. Returns NIL also if property is not available.
Get the item for key from blackboard. If there is no such key return default.
Groups elements in the sequence seq according to characteristic which is a function of one argument. Example:
(group-by #'second '((1 2) (2 2) (3 4) (4 4)))
Returns all subsets of set with length between k and l. Example:
(k->l-subsets '(1 2 3) 1 2) ⇒ ((1) (2) (3) (1 2) (1 3) (2 3))
Returns all subsets of set with length k. Example:
(k-subsets '(1 2 3) 2) ⇒ ((1 2) (1 3) (2 3))
Iterates body over items. Example:
(let ((x (make-array 10)) (y (make-list 10 :initial-element 1))) (loop+ ((xc x) (yc y) i) doing (setf xc (+ i yc)) finally (return x)))
Call func given in the first argument on each key of hash-table. func must return the new key and the new value as two values. Those pairs are stored in a new hash-table.
Maps the elements of list in a hash-table identified by identifier. func is evaluated on each element and produces two values which are used as key and value for the hash-table.
Applies func to a product of lists. Example:
(map-product #'cons '(2 3) '(1 4)) ⇒ ((2 . 1) (2 . 4) (3 . 1) (3 . 4))
Maps tree using func. Example:
(map-tree #'1+ '((1 (2)))) ⇒ ((2 (3)))
Collects the arguments with which a mapping construct calls a given function. E.g.
(mapper-collect #'mapc '(3 4 5)) ⇒ (3 4 5)
Counts the arguments with which a mapping construct calls a given function. E.g.
(mapper-sum #'mapc '(3 4 5)) ⇒ 3
Tests if the test is fulfilled for every argument on which the mapper is called:
(mapper-every #'plusp #'mapc '(3 4 5)) ⇒ T
Select the arguments with which a mapping construct calls a given function. E.g.
(mapper-select-first #'mapc '(3 4 5) '(7 8 9)) ⇒ 3,7
Tests if the test is fulfilled for some argument on which the mapper is called:
(mapper-some #'plusp #'mapc '(-3 4 5)) ⇒ T
Sums the arguments with which a mapping construct calls a given function. E.g.
(mapper-sum #'mapc '(3 4 5)) ⇒ 12
Finds a maximally connected set by taking the union of the elements in connected with the sets of disconnected-sets. Returns the maximally connected sets and the remaining disconnected ones. Example:
(maximally-connected '(1 2) '((3 4) (2 3) (5 6)) :test #'intersection :combine #'union) ⇒ (1 2 3 4), ((5 6))
Memoizes the function func which should be a non-recursive function of one argument.
Memoizes multi-argument functions named by the symbol funsym.
As a global macro it memoizes the following function definition. Inside a
with-memoizationenvironment, it memoizes its function argument.
The body is memoized for the keys given as a list of bindings.
Returns a list of all ordered partitions of k into n natural numbers. Example:
(n-partitions-of-k 2 3) ⇒ ((0 3) (1 2) (2 1) (3 0))
Returns a sequence of the same type as seq consisting of its partial sums.
Checks if perm is a possible permutation vector. A permutation pi is characterized by a vector containing the indices from 0,...,
length(perm)-1 in some order.
A permutation perm acts on the vector v by permuting it according to result[i] = v[perm[i]].
Returns a list of all positive ordered partitions of k into n natural numbers. Example:
(positive-n-partitions-of-k 2 3) ⇒ ((1 2) (2 1))
Returns a list of all positive ordered partitions of k. Example:
(positive-partitions-of-k 3) ⇒ ((1 2) (2 1))
A mixin which adds a slot of properties to the class.
Direct slots:
- PROPERTIES: A property list which is used to store unstructured information about this object.
Queue class accessed with
enqueueanddequeue.Direct slots:
- HEAD: Self-explanatory.
- TAIL: Self-explanatory.
Range of numbers for iteration.
Direct slots:
- FROM: Start of range, defaults to 0.
- TO: Inclusive end of range, defaults to infinity.
- BELOW: Exclusive end of range, defaults to infinity.
- BY: Step size.
Calling this function results in an error. Such a call may be used as default form when an argument should be supplied.
Removes the items marked by keys from the property list plist. This function was posted at 2.12.2002 to the comp.lang.lisp newsgroup by Erik Naggum.
Direct slots:
- SIZE: Self-explanatory.
- TEST: Self-explanatory.
- STORE: Self-explanatory.
This is a hash-table where entries are guaranteed to be accessed in the order in which they are interned.
Direct slots:
- TEST: Self-explanatory.
- STORE: Self-explanatory.
- ITEM-STORE: Self-explanatory.
Breaks the list items in pieces of lengths determined by nrins. Example:
(split-by-length '(1 2 3 4) '(1 3)) ⇒ ((1) (2 3 4))
Transfer items between the blackboards from-bb and to-bb. When ensure is set, an existing item is not modified.
Performs certain translations from an association table on the string item. Example: (translate "abcdefg" '(("a" . "x") ("b" . "yz")))
Work with the items on blackboard corresponding to properties. If some property is a list, the second element is the default value and the third is an alias to be used to refer to this parameter. Example:
(with-items (&key sol (rhs nil rhs-high)) blackboard (setq sol rhs-high))
Sets up a memoization environment consisting of a table, and a captured symbol
memoizing-letmemoizing its body depending on the arguments. Example of usage:(with-memoization (:type :local :id 'test) (defun test (n) (memoizing-let ((k (* 2 n))) (sleep 1) (* k k))))If type is :global, the table is thread-safe and the same for all threads, if type is :local, it is special for each thread.