Re: Using (CASE ...) with strings?
- From: jjjacobson@xxxxxxxxx
- Date: 30 Oct 2006 16:10:03 -0800
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
.
- References:
- Re: Using (CASE ...) with strings?
- From: Ken Tilton
- Re: Using (CASE ...) with strings?
- Prev by Date: Re: nested presentations
- Next by Date: OT: Stern Environmental Review, a British Government Report published Online
- Previous by thread: Re: Using (CASE ...) with strings?
- Next by thread: Efficiency of arrays in LISP
- Index(es):