Today when I did a new interface to my interface [1]
to `google-translate' which is an interface to
Google Translate, I used `cl-case' with strings but
was frustrated with failure, because `cl-case' uses
equality function(s) that report nil for
identical strings.
So I wrote this.
I guess I like it fine - so far.
(defun string-case (string &rest clauses)
"Search for STRING in CLAUSES and return the corresponding value.\n
CLAUSES is a list of elements of the form ((KEY-1 ... KEY-N) VALUE).
If STRING is a `member' of (KEY-1 ... KEY-N), return VALUE.\n
The default clause is (t DEFAULT-VALUE).
When found, DEFAULT-VALUE is unconditionally returned.
Subsequent clauses are discarded, because clauses are examined left-to-right.
This is also factor if STRING matches keys in several clauses.\n
If there isn't a default clause, nil is returned if STRING isn't a key."
(if clauses
(let*((c (car clauses))
(keys (car c)) )
(if (or (member string keys) ; on match or
(eq keys t) ) ; default
(cadr c) ; return value
(apply `(string-case ,string ,@(cdr clauses))) ))))
[1]
http://user.it.uu.se/~embe8573/conf/emacs-init/translate.el
--
underground experts united
http://user.it.uu.se/~embe8573