More exporting and string stuff

master
Ringo Wantanabe 6 years ago
parent e18e5f9561
commit 1de7750917
No known key found for this signature in database
GPG Key ID: DDDD9B6759158726

@ -7,7 +7,7 @@
(defparameter *-utils-lisp* t) (defparameter *-utils-lisp* t)
(defparameter *-utils-depends* '(#:cl-ppcre)) (defparameter *-utils-depends* '(#:cl-ppcre))
(defparameter *-utils-version* "0.1.3") (defparameter *-utils-version* "0.1.4")
;;; -- Handle internal exporting -- ;;; -- Handle internal exporting --
@ -63,6 +63,7 @@
;;; --- actual (exported) code goes here --- ;;; --- actual (exported) code goes here ---
(defun where (expr items) (defun where (expr items)
(mapcan #'(lambda (x) (mapcan #'(lambda (x)
(when (funcall expr x) (list x))) (when (funcall expr x) (list x)))
@ -82,8 +83,8 @@
(loop for line = (funcall read-line input nil) (loop for line = (funcall read-line input nil)
while line do (funcall fi line))) while line do (funcall fi line)))
(defmacro strcat (&rest str) (defun strcat (&rest str)
`(apply #'concatenate (cons 'string ,@str))) (apply #'concatenate (cons 'string str)))
(defmacro until (stmt) (defmacro until (stmt)
`(let ((ret nil)) `(let ((ret nil))
@ -124,6 +125,65 @@
`(let ((vv ,val)) `(let ((vv ,val))
(if (funcall ,test vv) vv ,or))) (if (funcall ,test vv) vv ,or)))
(defun get-all-symbols ()
(let ((lst '()))
(do-all-symbols (s lst)
(push s lst))
lst))
(defun symbol-match (scan &optional (symbols nil))
(let ((symbols (val-if-or symbols #'true
(get-all-symbols))))
(where #'(lambda (x) (cl-ppcre:scan scan (write-to-string x)))
symbols)))
(defun index (i max)
(if (< i 0)
(index (+ max i) max)
(mod i max)))
(defun slice (seq start end)
"only works with lists i guess"
(let ((start (index start (length seq)))
(end (index end (length seq))))
(rplacd (nthcdr end seq) nil)
(nthcdr start seq)))
(defun flatten-top-level (li)
(mapcan #'(lambda (x)
(if (atom x) (list x) x))
li))
(defun flatten (li)
(mapcan #'(lambda (x)
(if (atom x)
(list x)
(flatten x)))
li))
(defun strjoin (delim &rest strs)
(let ((strs (flatten-top-level strs)))
(apply #'strcat
(slice
(mapcan #'(lambda (x)
(list x delim))
strs)
0 -2))))
(defun export-struct (struct &optional (symbols nil))
(mapc #'export (symbol-match (strcat "^" (write-to-string struct) "-") symbols)))
(defun -export*-struct (structs &optional (symbols nil))
(mapc #'export (symbol-match
(strcat
"^("
(strjoin "|" (mapcar #'write-to-string structs))
")-")
symbols)))
(defmacro export*-struct (&rest structs)
`(-export*-struct '(,@structs)))
(defmacro popto (li val &key (test #'eql)) (defmacro popto (li val &key (test #'eql))
"pop() list <li> until (car li) is equal to <val>, return elements pop()ed in new list" "pop() list <li> until (car li) is equal to <val>, return elements pop()ed in new list"
`(loop while (not (funcall ,test (car ,li) ,val)) `(loop while (not (funcall ,test (car ,li) ,val))

Loading…
Cancel
Save