-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.lisp
More file actions
46 lines (41 loc) · 1011 Bytes
/
strings.lisp
File metadata and controls
46 lines (41 loc) · 1011 Bytes
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
44
45
(in-package #:pjs-utils)
(defun sconc (&rest args)
"string joining with less typing !"
(apply #'concatenate (cons 'string args)))
(define-compiler-macro sconc (&environment env &rest args)
(compile-time-sconc env args))
(defun compile-time-sconc (env args)
(let (args*
constant
(args (remove-if #'null-string-p
(mapcar (lambda (arg)
(megaexpand arg env))
args))))
(flet ((emit-constant ()
(when constant
(push constant args*)
(setf constant nil))))
(dolist (arg args)
(if (or (stringp arg)
(null arg))
(if constant
(setf constant (concatenate 'string constant arg))
;; else
(setf constant arg))
;; else
(progn
(emit-constant)
(push arg args*))))
(if args*
(progn
(emit-constant)
`(concatenate 'string ,@(nreverse args*)))
;; else
(if constant
constant
;; else
"")))))
(defun null-string-p (str)
(or (null str)
(and (stringp str)
(= 0 (length str)))))