-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.lisp
35 lines (32 loc) · 1.22 KB
/
util.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
(in-package :with)
(defmacro listify (thing)
`(if (listp ,thing)
,thing
(list ,thing)))
;;------------------------------------------------------------------------------
;; create a single string from a thing, converting named objects such as
;; packages, symbols and foreign-types into strings.
;; Anything else? format it!
;;
;;
(defun as-string (thing)
"Create a string from thing. If thing is a list or tree, flatten"
(typecase thing
(string thing)
(symbol (symbol-name thing))
(package (package-name thing))
(cffi::foreign-type (symbol-name (cffitype-symbol thing)))
(t (format nil "~S" thing))) )
;;------------------------------------------------------------------------------
;; catstring create a string from a bunch of things
;; Macro to avoid evaluation, so (catstring x y z) works
(defun catstring (&rest things)
"Convert every thing to a string, and return concatenation."
(apply #'concatenate 'string (mapcar #'as-string things)))
;;
;; symbolicate - create a symbol from a bunch of things
(defun symbolicate (&rest things)
(intern (apply #'catstring things)))
(defun find-symbol-or-die (name package &rest rest)
(or (find-symbol name package)
(apply #'error rest)))