This is the clith Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Tue Jul 15 04:39:55 2025 GMT+0.
The main system appears first, followed by any subsystem dependency.
Modules are listed depth-first from the system components tree.
clith/src
clith
(system).
package.lisp
(file).
clith.lisp
(file).
definitions.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
clith/src/clith.lisp
package.lisp
(file).
src
(module).
canonize-binding
(function).
check-binding
(function).
check-bindings
(function).
check-defwith
(function).
check-vars
(function).
expand-binding-expression
(function).
expand-with-expansion
(function).
extract-declaration-single-var
(function).
extract-declarations
(function).
extract-var-declarations
(function).
make-with-form
(function).
make-with-macro-form
(function).
split-declarations
(function).
var-declaration-p
(function).
with-expansion-p
(function).
with-macro-binding-p
(function).
clith/src/definitions.lisp
clith.lisp
(file).
src
(module).
Packages are listed by definition order.
clith
alexandria
.
common-lisp
.
canonize-binding
(function).
check-binding
(function).
check-bindings
(function).
check-defwith
(function).
check-vars
(function).
expand-binding-expression
(function).
expand-with-expansion
(function).
extract-declaration-single-var
(function).
extract-declarations
(function).
extract-var-declarations
(function).
make-with-form
(function).
make-with-macro-form
(function).
split-declarations
(function).
var-declaration-p
(function).
with-expansion-p
(function).
with-macro-binding-p
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Define a WITH expansion. A WITH expansion controls how the macro WITH is expanded. This macro has
the following syntax:
(DEFWITH name (vars args with-body) declaration* body*)
name ::= symbol
vars ::= symbol | (var-with-options*)
var-with-options ::= symbol | (symbol option*)
option ::= destructuring-lambda-argument
args ::= destructuring-lambda-list
with-body ::= symbol
declaration ::= declaration-form | docstring
body ::= form
When using (NAME ARGS*) inside the macro WITH, it will expand to the value returned by DEFWITH.
The variables to be bound are passed through VARS (VARS will always be a list) and the arguments passed
to NAME are bound to ARGS. Finally, WITH-BODY is bound to the body of the WITH macro. Keep in mind that
WITH-BODY can contain declarations.
As an example, let’s define the with expansion MY-FILE. We will make WITH to be expanded to WITH-OPEN-FILE.
(defwith my-file (vars (filespec &rest options) body)
"Open a file."
(with-gensyms (stream)
‘(with-open-file (,stream ,filespec ,@options)
(multiple-value-bind ,vars ,stream
,@body))))
As VARS is always a list, we can use MULTIPLE-VALUE-BIND in case additional variables are passed.
Also, we are assuming here that no additional options are passed with the variables to be bound.
Now, using WITH:
(with ((file (my-file "~/file.txt" :direction :output)))
(print "Hey!" file))
Finally, note that we put a docstring when we defined MY-FILE. We can retrieve it with DOCUMENTATION:
(documentation ’my-file ’with) ;; –> "Open a file."
This macro has the following systax:
(WITH (binding*) declaration* form*)
binding ::= symbol | ([vars] form)
vars ::= symbol | (var-with-options*)
var-with-options ::= symbol | (symbol var-option*)
var-option ::= form
WITH accepts a list of binding clauses. Each binding clause can be a symbol or a list. Depending on
this, the behaeviour of WITH is slightly different:
- A symbol: The symbol is bound to NIL.
(with (x) ; X is bound to NIL
...)
- A list with one element. That element can be a WITH expansion or not:
* A WITH expansion: The form is expanded according to DEFWITH. In this case,
the WITH expansion will receive NIL as the list of variables to be bound.
(with (((init-video-system))) ; Possible expansion that should finalize the video system at the end
;; Doing video stuff
)
* Otherwise: The form is placed untouched. It will be evaluated normally.
(with (((print 3))) ; Just prints 3
...)
- A list with two elements: The first element must be a symbol or a list of symbols with
or without options. The second element is a form that can be a WITH expansion:
* A WITH expansion: The form is expanded according to DEFWITH.
(with ((my-file (open "~/my-file.txt"))) ; Expanded to WITH-OPEN-FILE
...)
* Otherwise: The form is placed into a MULTIPLE-VALUE-BIND expression.
(with ((x 3)
((y z) (floor 4 5))) ; Forms placed into MULTIPLE-VALUE-BIND
...)
Binding clauses that uses a WITH expansion accepts an extended syntax. Each variable can have options.
These options should be used inside DEFWITH to control the expansion with better precision:
(defwith slots (vars (object) body)
‘(with-slots ,vars ,object
,@body))
(defstruct 3d-vector x y z)
(with ((v (make-3d-vector :x 1 :y 2 :z 3))
((x (up y) z) (slots v)))
(+ x up z))
Macros and symbol-macros are treated specially. If a macro or symbol-macro is used, they
will be expanded with MACROEXPAND-1 and its result is the form, or WITH expansion, this macro uses.
Checks wether a symbol denotes a WITH expansion.
Transforms BINDING to a form that is more apropiate to process.
In particular, turns BINDING into a list of two elements.
The former element is a list of the binding symbols written by user.
The latter is the form that returns the values which variables will be bound to.
Checks the syntax of a binding clause.
Checks the syntax of binding clauses.
Checks the syntax of variables.
If extendedp, it is accepted to have options after a variable.
I.e. if extendedp, a variable can be a list with a symbol followed by other forms.
Returns the actual expression to be used inside a binding clause.
Expands a WITH expansion.
Splits DECLARATIONS into two lists of declarations. The former is a list of declarations that applies to VAR. The latter are the rest of declarations.
Extracts the declarations of BODY.
Splits DECLARATIONS into two lists of declarations.
The former is a list of declarations that applies to one variable in VARS.
The latter are the rest of declarations.
Returns the WITH macro expansion.
Expands a WITH expansion given its BINDING, its BODY and its DECLARATION.
Splits DECLARATIONS into two lists.
The former is a list of declarations that applies to one of the variables used in CANONIZED-BINDINGS.
The latter are the rest of declarations.
Checks if ID is an identifier of a variable declaration.
Checks if a expression is a with expansion.
Checks if a binding has a custom expansion.
Jump to: | C D E F M S V W |
---|
Jump to: | C D E F M S V W |
---|
Jump to: | C D F M P S |
---|
Jump to: | C D F M P S |
---|