-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lisp
43 lines (37 loc) · 1.51 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
41
42
43
;;;; utils.lisp
(in-package #:yarty)
;;;; General
(defmacro assocf (key val place &rest keyargs &environment env)
"Sets first instance of key in alist to val, adding entry if necessary."
(multiple-value-bind (vars vals bind set access)
(get-setf-expansion place env)
(alexandria:with-gensyms (gkey gval cons gaccess)
`(let ((,gkey ,key)
(,gval ,val))
(let* (,@(mapcar #'list vars vals)
(,gaccess ,access))
(multiple-value-bind ,bind
(let ((,cons (assoc ,gkey ,gaccess ,@keyargs)))
(if ,cons
(prog1 ,gaccess
(setf (cdr ,cons) ,gval))
(acons ,gkey ,gval ,gaccess)))
,set))))))
(defmacro ensure-dynamic-bindings ((&rest symbols) &body body)
"Ensure symbols are dynamically bound without shadowing extant bindings."
(alexandria:with-gensyms (unbound)
`(let ((,unbound (remove-if #'boundp ',symbols)))
(progv ,unbound ',(make-list (length symbols))
(locally (declare (special ,@symbols))
,@body)))))
(defun function-name-p (form)
;; Form might not yet have an fdefinition when this is called,
;; e.g. it could be defun'd in the same file.
(and form
(symbolp form)
(not (special-operator-p form))
(not (macro-function form))))
(defun quit (exit-code)
#+sbcl (sb-ext:quit :unix-status exit-code)
#+ccl (ccl:quit exit-code)
#-(or ccl sbcl) (warn "YARTY::QUIT not yet ported to this implementation."))