Coverage report: /home/ellis/.stash/quicklisp/dists/quicklisp/software/alexandria-20241012-git/alexandria-1/binding.lisp
Kind | Covered | All | % |
expression | 0 | 53 | 0.0 |
branch | 0 | 12 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
(in-package :alexandria)
3
(defmacro if-let (bindings &body (then-form &optional else-form))
4
"Creates new variable bindings, and conditionally executes either
5
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.
7
BINDINGS must be either single binding of the form:
9
(variable initial-form)
11
or a list of bindings of the form:
13
((variable-1 initial-form-1)
14
(variable-2 initial-form-2)
16
(variable-n initial-form-n))
18
All initial-forms are executed sequentially in the specified order. Then all
19
the variables are bound to the corresponding values.
21
If all variables were bound to true values, the THEN-FORM is executed with the
22
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
24
(let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
27
(variables (mapcar #'car binding-list)))
33
(defmacro when-let (bindings &body forms)
34
"Creates new variable bindings, and conditionally executes FORMS.
36
BINDINGS must be either single binding of the form:
38
(variable initial-form)
40
or a list of bindings of the form:
42
((variable-1 initial-form-1)
43
(variable-2 initial-form-2)
45
(variable-n initial-form-n))
47
All initial-forms are executed sequentially in the specified order. Then all
48
the variables are bound to the corresponding values.
50
If all variables were bound to true values, then FORMS are executed as an
52
(let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
55
(variables (mapcar #'car binding-list)))
57
(when (and ,@variables)
60
(defmacro when-let* (bindings &body body)
61
"Creates new variable bindings, and conditionally executes BODY.
63
BINDINGS must be either single binding of the form:
65
(variable initial-form)
67
or a list of bindings of the form:
69
((variable-1 initial-form-1)
70
(variable-2 initial-form-2)
72
(variable-n initial-form-n))
74
Each INITIAL-FORM is executed in turn, and the variable bound to the
75
corresponding value. INITIAL-FORM expressions can refer to variables
76
previously bound by the WHEN-LET*.
78
Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
79
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
81
(let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
84
(labels ((bind (bindings body)
86
`(let (,(car bindings))
87
(when ,(caar bindings)
88
,(bind (cdr bindings) body)))
90
(bind binding-list body))))