Home   my Lisp code 

standard-cl: a general-purpose library for Common Lisp

Lots of random useful stuff. Please note that this page isn't updated as often as the code, so it might not always be up to date.

lett x expr &body body
Binds a single variable, as in (let ((x expr)) ...), or a list of variables, as in destructuring-bind.

def, defx, indef, indefx
same as defun, plus the function greturn is defined locally to return from the the (global) function, and the local variable gfuncname is bound to the function's name. A -x suffix means export the function, and an in- prefix means inline it.

defmac, macx
defmac is an abbreviation for defmacro, and macx is the same as defmac, plus it exports the macro.

in-defpackage name &rest options
defpackage + in-package

with-gensyms name-forms, with-gensym name-form
same as in PCL and On Lisp, except optional string names are allowed. Each name form can be either a name or a two-element list containing a name and a string. with-gensym creates a single symbol, no parens needed, except for a string name.

abbreviations

no = null (stolen from Arc) letvals = multiple-value-bind
concat = concatenate concstr = apply #'concat 'string
ask-yn = y-or-n-p defparam = defparameter
sethash = (setf gethash)

2-fix abbreviations

isatom = atom islist = listp
iscons = consp ischar = characterp
isnum = numberp isint = integerp
=0 = zerop >0 = plusp
<0 = minusp

while, do-while, until, do-until
standard loops

do-hashtable (key val table &optional (rtrnval nil)) &body body
hashtable iterator

echo &rest args
prints format-style arguments to *standard-output* with a terminal newline

prompt &rest args
prints format-style arguments to *standard-output* and forces completion of output

pause &rest args
calls prompt with its arguments, and waits for a carriage return.

dotimes1, dorange
same as dotimes, except dotimes1 starts at 1 and includes the upper limit, and both endpoints are specified in dorange

times, times1, range, range*
functions that return lists of consecutive integers

count-list (n val list &optional result) &body body
dolist and dotimes combined

has-length list n
list length predicate, guaranteed to terminate

andf, orf, xorf
first-class boolean functions (non-shortcutting)

/_   /.
integer and floating-point division
/_ = floor ° /
/. = float ° /

+=   -=   *=   //=   /_=   /.=
C-style rebinding operators

or= and= not= xor=
Perl-style boolean extensions of C assignment operators

length< length= length>
length comparisons

sum, prod
+ and * for lists

^ ^2 ^3 ^4 e^ 2^ 10^
exponentiation

defvars, defparams, defconstants
multiple variable declarations

is-lc is-uc is-letr lc<-int uc<-int, int<-letr
Upper- and lower-case letters are mapped to the integers 0–25 in alphabetical order. IS-* functions are predicates, *<-* indicates coersion

eif if-true &body if-false
Elisp-style IF operator. The body constitutes the second (and last) branch of a CL IF form, wrapped in an implicit progn.

flatten
flattens a list (one level)

pushlist, npushlist, pushrevlist
appends one list onto another, and stores the result in the place originally occupied by the second list.

pushwhen, letwhen, setfwhen
executes the corresponding operation only when the value is non-nil

trim-whitespace, trim-linespace
string-trim #\Space and #\Tab, with or without #\Newline

cond-eql, strcase
equivalents of CASE for eql and string=

dovector
interates over a vector

letstruct
binds the fields of a structure

docells
iterates over the cells (conses) of a list

dopairs
iterates over all (unordered) pairs of values in a list

splitlist
returns two lists of values from a single list, separated according to a predicate

variance, rms
statistical functions

quit
a portable way to exit Lisp. stolen from someone on c.l.l


© 2008 Daniel S. Bensen   Home   About   Site map