This package contains utilities that I find useful in writing programs; that is, it is a collection of generally-useful functions and macros. Some of these I've written, and some of these derive from other sources.
The utilities can be categorised as
hash-table
functions,mkstr
: concatenates its symbols and returns the printable representation
of the resultsymb
: passes its arguments to mkstr
to produce a printable representation, and returns the symbol built
from this result; if the symbol does not exist, it will be
created.group
: takes a list as input and produces a
list of sublists of length n.flatten
: Returns a list of all atoms present in
the provided list.compose
: allows a number of functions with the same arity
to be composed together in a chain.defmacro!
: provides automatic gensyms and
once-only evaluation. Arguments that begin with g! will be
automatically gensym
'd, and arguments that begin with
o! will only be evaluated once. Inside the body, the o! arguments
should be called as their equivalent g! argument: o!x should be
called in the body as g!x.
sethash
: convenience function for setting a value
in a hash table.hashkeys
: returns a list of all the keys in a hash
table.hash-table-to-alist
: converts the hash table to an
alist of (key . value)
pairs.alist-to-hash-table
: converts an alist to a hash
table.enable-hash-table-reader
: enables the reader
macro #{}#
for hash tables. The resulting hash-table
will use #'equal for equality. For example,
#{:a :b :c :d}#will create a hash-table with the keys
:a
and :c
. :a
stores the value :b
,
and :c
stores the value :d
.interpose
: places a separator between each element
of a list.build-list
: if arg is an atom, return it as a
list. If it's a list, return the arg. If it's a vector, coerce it
to a list. Otherwise, return nil.partial
: provides partial function application. It
returns a lambda that will call the function given with the intial
args and any additional args provided to the lambda.macroexpand-n
: expand the macro n times.mksymb
: creates a symbol from its arguments,
upcasing strings as required.mkkw
: creates a keyword from its arguments.defclass!
: convenience macro for quickly defining
a class with slots and a docstring.Clone into your Quicklisp project's local-projects/
subdirectory, and call (ql:quickload :kutils)
.
You can browse the Github repository.