This is the cl-hash-util Reference Manual, version 0.1.7, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:01:17 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
cl-hash-util
A simple and natural wrapper around Common Lisp’s hash functionality.
Andrew Danger Lyon <orthecreedence@gmail.com>
MIT
0.1.7
hash-util.lisp
(file).
more-hash-util.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
cl-hash-util/hash-util.lisp
cl-hash-util
(system).
*error-on-nil*
(special variable).
hash
(macro).
hash-copy
(function).
hash-create
(function).
hash-keys
(function).
hash-merge
(function).
hget
(function).
(setf hget)
(function).
%find-lowest-store
(function).
%hget-access
(function).
%hget-set
(function).
%store-p
(function).
cl-hash-util/more-hash-util.lisp
hash-util.lisp
(file).
cl-hash-util
(system).
alist->hash
(function).
alist->plist
(function).
collecting-hash-table
(macro).
hash->alist
(function).
hash->plist
(function).
plist->alist
(function).
plist->hash
(function).
with-keys
(macro).
%hash-collecting-modes
(function).
mkstr
(function).
symbolize
(function).
Packages are listed by definition order.
cl-hash-util
hu
common-lisp
.
common-lisp-user
.
*error-on-nil*
(special variable).
alist->hash
(function).
alist->plist
(function).
collecting-hash-table
(macro).
hash
(macro).
hash->alist
(function).
hash->plist
(function).
hash-copy
(function).
hash-create
(function).
hash-get
(function).
(setf hash-get)
(function).
hash-keys
(function).
hash-merge
(function).
hget
(function).
(setf hget)
(function).
plist->alist
(function).
plist->hash
(function).
with-keys
(macro).
%find-lowest-store
(function).
%hash-collecting-modes
(function).
%hget-access
(function).
%hget-set
(function).
%store-p
(function).
mkstr
(function).
symbolize
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
If hget encounters a nil, error out.
A collection macro that builds and outputs a hash table. To add to the hash
table, call the collect function with a key and a value from within the scope
of the collecting-hash-table macro. The value will be inserted or combined with
existing values according to the specified mode.
This code collects words into bins based on their length:
“‘common-lisp
(collecting-hash-table (:mode :append)
(dotimes (i 10)
(let ((word (format nil "~r" i)))
(collect (length word) word)))
“‘
Result: <hash table: 5 => ("three" "seven" "eight")
3 => ("one" "two" "six")
4 => ("zero" "four" "five" "nine")>
The mode can be set in the parameters section of collecting-hash-table with the :mode keyword. The :mode keyword can also be passed to individual collect calls.
Keyword parameters:
:test - Test function parameter passed to make-hash-table when creating a new
hash table
:existing - Pass an existing hash table to the macro for modification. Using
this option at the same time as :test will result in an error.
:mode - Set the default mode for the collect function. Modes are :replace :keep :tally :sum :append :push :concatenate or a function that will be applied in a reduce-like fashion to the existing and new values of a key.
Extends hash-create syntax to make it nicer.
With-keys is the hash table equivalent of with-slots.
(with-keys
("name" (loc "location") (time "time" 2024))
(hash ("name" "andrew") ("location" "santa cruz"))
(setf loc (string-upcase loc))
(format nil "Hi, ~a in ~a around ~a!" name loc time))
"Hi, andrew in SANTA CRUZ around 2024!"
The first parameter is a list of keys that with-keys will reference in the hash
table provided in the second parameter. With-keys will attempt to convert each
key into a symbol, binding the hash table value to it during body execution.
String keys are upcased before conversion to symbols.
If you don’t want with-keys to guess at a symbol for a key, supply a list -
(<symbol> <key>) - in place of the key, as in (loc "location") above.
If you want to supply a default value, you have to supply a list - (<symbol> <key> <default>) - in place of the key, as in (time "time" 2024).
Converts an alist to a hash table.
The :existing keyword can be used to supply a hash table to which the contents
of the alist will be added. Otherwise, a new hash table is created.
Since alists can contain multiple entries for a given key, alist->hash has a
variety of accumulation modes to handle them. The accumulation mode can be
set with the :mode keyword. Available modes are :replace :keep :tally :sum
:append and :push. :replace is the default.
If a function is supplied instead of a recognized mode, then values will be accumulated to each key as by a reduce of the function.
Converts an alist to a plist
Converts a hash table to an alist
Converts a hash table to a plist
Performs a shallow (non-recursive) copy of a hash table.
Create a hash table with limited syntax:
(hash ‘(("name" "andrew") ("city" "santa cruz")))
which would otherwise be:
(let ((hash (make-hash-table :test #’equal)))
(setf (gethash "name" hash) "andrew")
(setf (gethash "city" hash) "santa cruz")
hash)
yuck city.
Allows you to specify a path to get values out of a hash/list object. For
instance, if you did:
(let ((myhash (hash ’("lol" ’(3 4 5)))))
(hget myhash ’("lol" 1)))
which would return 4 (1st index of list stored under key ’lol of the hash
table). Simplifies traversing responses from decoded JSON objects by about a
trillion times.
The second and third values returned by hget indicate how much success it had
in looking up your request. If the second value is T, everything was found,
right up to the end node. When the second value is NIL, the third value is
the portion of the supplied path that was missing.
By setting *error-on-nil* to true, hget can be persuaded to throw an error if any of the upper part of the tree is missing . It will not throw an error if the final value is not set.
hget
.
Defines a setf for the hget function. Uses hget to get all but the
last item in the path, then setfs that last object (either a gethash or an
elt).
If any of the path aside from the last item is missing, it will throw an error. To change this behavior, supply an object construction function with the :fill-func parameter. (Setf hget) will fill out the tree up to the last path item with the objects that this function returns.
Grab all the hash keys of the passed hash into a list.
Returns a merged hash-table.
If a key occurs more than one time, the first key value is used
and subsequent key values are discarded.
For keeping the last value of a key, reverse the hash-table order.
Allows you to specify a path to get values out of a hash/list object. For
instance, if you did:
(let ((myhash (hash ’("lol" ’(3 4 5)))))
(hget myhash ’("lol" 1)))
which would return 4 (1st index of list stored under key ’lol of the hash
table). Simplifies traversing responses from decoded JSON objects by about a
trillion times.
The second and third values returned by hget indicate how much success it had
in looking up your request. If the second value is T, everything was found,
right up to the end node. When the second value is NIL, the third value is
the portion of the supplied path that was missing.
By setting *error-on-nil* to true, hget can be persuaded to throw an error if any of the upper part of the tree is missing . It will not throw an error if the final value is not set.
Defines a setf for the hget function. Uses hget to get all but the
last item in the path, then setfs that last object (either a gethash or an
elt).
If any of the path aside from the last item is missing, it will throw an error. To change this behavior, supply an object construction function with the :fill-func parameter. (Setf hget) will fill out the tree up to the last path item with the objects that this function returns.
Converts a plist to an alist
Converts a plist to a hash table.
The :existing keyword can be used to supply a hash table to which the contents
of the plist will be added. Otherwise, a new hash table is created.
Since plists can contain multiple entries for a given key, plist->hash has a
variety of accumulation modes to handle them. The accumulation mode can be
set with the :mode keyword. Available modes are :replace :keep :tally :sum
:append and :push. :replace is the default.
If a function is supplied instead of a recognized mode, then values will be accumulated to each key as by a reduce of the function.
Is the object something from which key could be fetched?
Jump to: | %
(
A C F H M P S W |
---|
Jump to: | %
(
A C F H M P S W |
---|
Jump to: | *
S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
* | |||
*error-on-nil* : | Public special variables | ||
| |||
S | |||
Special Variable, *error-on-nil* : | Public special variables | ||
|
Jump to: | *
S |
---|
Jump to: | C F H M P S |
---|
Jump to: | C F H M P S |
---|