added switch

added split-string
master
Avril 4 years ago
parent 01442bcf77
commit b9836a7f26
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -576,6 +576,27 @@
; --- others ; --- others
(defmacro switch (value &body conds)
"Cond `eql' for value to each first element of `conds', with the result as the 2nd element. If `conds' is an atom, it is treated as the default condition"
(let* ((value-name (gensym))
(exprs (mapcar #'(lambda (pair)
(if (atom pair)
`(t ,pair)
`((eql ,value-name ,(car pair)) ,(cadr pair)))) conds)))
`(let ((,value-name ,value))
,(cons 'cond exprs))))
(defun split-string (string &optional sep)
"Split a string by this seperator (or `:whitespace', if not provided"
(let* ((sep (or (switch sep
(nil "\\s")
nil)
(cl-ppcre:quote-meta-chars sep)))
(lst (cl-ppcre:split sep string)))
(values (where #'(lambda (str) (> (length str) 0)) lst)
sep)))
(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