- Let macros
These are macros that combine a
letorlet*form with a test based on the results of the bindings. This is useful for reducing common boilerplate where a let is used to perform some operations, and some code should be executed based on the results of those bindings.For example, from
kmop/kmop.lisp:* (macroexpand-1 '(whenlet ((kwarg (slot-initarg slot)) (value (dispatch-get-value slot (slot-table-value slot ht snake-case)))) (list kwarg value))) (LET ((KWARG (SLOT-INITARG SLOT)) (VALUE (DISPATCH-GET-VALUE SLOT (SLOT-TABLE-VALUE SLOT HT SNAKE-CASE)))) (WHEN (AND KWARG VALUE) (LIST KWARG VALUE)))condlet(bindings &body forms)Evaluatebindingsin aletform, then evaluateformsin acond.condlet*(bindings &body forms)Evaluatebindingsin alet*form, then evaluateformsin acond.iflet(bindings &body (then &optional else))Evaluatebindingsin aletform; if they are all T, execute thethenform. Otherwise, execute theelseform.iflet*(bindings &body (then &optional else))Evaluatebindingsin alet*form; if they are all T, execute thethenform. Otherwise, execute theelseform.orlet(bindings &body body)For each set of bindings, evaluate them in sequence. If each binding evaluates to T, evaluatebodyin aprogn.(macroexpand-1 '(orlet ((cls (class-symbol s)) (slots (only-key-slots cls)) (args (json-slots tbl slots))) (apply #'make-instance cls args))) (LET ((CLD (CLASS-SYMBOL S))) (WHEN CLS (LET ((SLOTS (ONLY-KEY-SLOTS CLS))) (WHEN SLOTS (LET ((ARGS (JSON-SLOTS TBL SLOTS))) (WHEN ARGS (PROGN (APPLY #'MAKE-INSTANCE CLS ARGS))))))))unlesslet(bindings &body body)Evaluate the bindings in a let form; if they don't all evaluate to T, evaluatebodyin an implicitprogn.unlesslet*(bindings &body body)Evaluatebindingsin alet*form; if they are all not NIL, evaluatebody, which is wrapped in an implicitprogn.whenlet(bindings &body body)Evaluate the bindings in a let form; if they all evaluate to T, evaluatebodyin an implicitprogn.whenlet*(bindings &body body)Evaluatebindingsin alet*form; if they all evaluate to T, evaluatebody, which is wrapped in an implicitprogn.- File macros
These macros abstract common operations on files.
with-read-from-file((stream path &rest args &key (direction input directionp) &allow-other-keys) &body body)Openpathfor reading, bound tostream, with any remaining arguments passed towith-open-file, and executebody.with-write-to-file((stream path &rest args &key (direction output directionp) &allow-other-keys) &body body)Evaluatebodywith the file atpathopened and bound to the value ofstream. Any remaining keyword arguments are passed towith-open-file.The following two macros aren't yet able to be documented with Codex, as they are defined using the
defmacro!macro:read-file-as-string (path &rest args &key (direction nil directionp) &allow-other-keys)Read the contents of the file at
pathas a string. Any remaining arguments are sent towith-open-file.with-string-output-to-file ((path &rest args &key (direction :output directionp) &allow-other-keys) &body body)Evaluate
body, and callmkstron the result. Write the resulting string topath. Any remaining arguments are sent towith-open-file.- General
-
in(obj seq &key (test (function eql)) key deep)Returns T if
obj, is inseq.If
seqis a list,testis used to determine whether the object matches. Ifkeyis not NIL, it is applied to elements beforetest. Ifdeepis true,seqwill be flattened before checking the list.If
seqis a vector,testis used to determine whether the object matches. Ifkeyis not NIL, it is applied to elements beforetest.If
seqis a hash table,testdoes not apply; the hash table's test is used. Ifkeyis not NIL, it is applied toobjbefore looking it up.