Re: Using (CASE ...) with strings?



This would seem to work for many cases:

(defmacro mapcase (func-test keyform &body clauses)
`(cond ,@(loop for (test exec) in clauses collect
(if (or (eql test t) (eql test 'otherwise))
`(t ,exec)
`((funcall ,func-test ,keyform ,test) ,exec)))))

So the following can be used:
CL-USER> (mapcase #'string< "mystring2"
("mystring" (princ "Winner!"))
("mystring2" (princ "not good?"))
(otherwise (princ "...")))
....
"..."
CL-USER> (mapcase #'string> "mystring2"
("mystring" (princ "Winner!"))
("mystring2" (princ "not good?"))
(otherwise (princ "...")))
Winner!
"Winner!"
CL-USER> (mapcase #'string= "mystring2"
("mystring" (princ "Winner!"))
("mystring2" (princ "not good?"))
(otherwise (princ "...")))
not good?
"not good?"

.... *crickets* party over, all went home ...
Jay

.