| 1 |
(in-package #:lispworks) |
| 2 |
|
| 3 |
#+lispworks |
| 4 |
(eval-when (:compile-toplevel :load-toplevel :execute) |
| 5 |
(error "lw-compat is not needed in LispWorks.")) |
| 6 |
|
| 7 |
(define-modify-macro appendf (&rest lists) |
| 8 |
append "Appends lists to the end of given list.") |
| 9 |
|
| 10 |
(define-modify-macro nconcf (&rest lists) |
| 11 |
nconc "Appends lists to the end of given list by NCONC.") |
| 12 |
|
| 13 |
(defmacro rebinding (vars &body body) |
| 14 |
"Ensures unique names for all the variables in a groups of forms." |
| 15 |
(loop for var in vars |
| 16 |
for name = (gensym (symbol-name var)) |
| 17 |
collect `(,name ,var) into renames |
| 18 |
collect ``(,,var ,,name) into temps |
| 19 |
finally (return `(let ,renames |
| 20 |
(with-unique-names |
| 21 |
,vars |
| 22 |
`(let (,,@temps) |
| 23 |
,,@body)))))) |
| 24 |
|
| 25 |
(define-modify-macro removef (item &rest keys) |
| 26 |
(lambda (place item &rest keys &key test test-not start end key) |
| 27 |
(declare (ignorable test test-not start end key)) |
| 28 |
(apply #'remove item place keys)) |
| 29 |
"Removes an item from a sequence.") |
| 30 |
|
| 31 |
(defmacro when-let ((var form) &body body) |
| 32 |
"Executes a body of code if a form evaluates to non-nil, |
| 33 |
propagating the result of the form through the body of code." |
| 34 |
`(let ((,var ,form)) |
| 35 |
(when ,var |
| 36 |
(locally |
| 37 |
,@body)))) |
| 38 |
|
| 39 |
(defmacro when-let* (bindings &body body) |
| 40 |
"Executes a body of code if a series of forms evaluates to non-nil, |
| 41 |
propagating the results of the forms through the body of code." |
| 42 |
(loop for form = `(progn ,@body) then `(when-let (,(car binding) ,(cadr binding)) ,form) |
| 43 |
for binding in (reverse bindings) |
| 44 |
finally (return form))) |
| 45 |
|
| 46 |
(defmacro with-unique-names (names &body body) |
| 47 |
"Returns a body of code with each specified name bound to a similar name." |
| 48 |
`(let ,(mapcar (lambda (name) `(,name (gensym ,(symbol-name name)))) |
| 49 |
names) |
| 50 |
,@body)) |