@ -576,6 +576,27 @@
; --- 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 ) )
"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 ) )