-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.lisp
40 lines (31 loc) · 1.01 KB
/
utils.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;;;
;;; Utilities
;;;
(in-package #:closette)
;;; push-on-end is like push except it uses the other end:
(defmacro push-on-end (value location)
`(setf ,location (nconc ,location (list ,value))))
;;; (setf getf*) is like (setf getf) except that it always changes the list,
;;; which must be non-nil.
(defun (setf getf*) (new-value plist key)
(block body
(do ((x plist (cddr x)))
((null x))
(when (eq (car x) key)
(setf (car (cdr x)) new-value)
(return-from body new-value)))
(push-on-end key plist)
(push-on-end new-value plist)
new-value))
;;; mapappend is like mapcar except that the results are appended together:
(defun mapappend (fun &rest args)
(if (some #'null args)
()
(append (apply fun (mapcar #'car args))
(apply #'mapappend fun (mapcar #'cdr args)))))
;;; mapplist is mapcar for property lists:
(defun mapplist (fun x)
(if (null x)
()
(cons (funcall fun (car x) (cadr x))
(mapplist fun (cddr x)))))