[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"cl-case" with strings
From: |
Emanuel Berg |
Subject: |
"cl-case" with strings |
Date: |
Thu, 04 Feb 2016 02:13:47 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
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
- "cl-case" with strings,
Emanuel Berg <=
- Re: "cl-case" with strings, Dmitry Gutov, 2016/02/03
- Re: "cl-case" with strings, Marcin Borkowski, 2016/02/04
- Re: "cl-case" with strings, Emanuel Berg, 2016/02/04
- Re: "cl-case" with strings, Stefan Monnier, 2016/02/04
- Re: "cl-case" with strings, Emanuel Berg, 2016/02/04
- Re: "cl-case" with strings, Dmitry Gutov, 2016/02/04
- Re: "cl-case" with strings, Emanuel Berg, 2016/02/04
- Re: "cl-case" with strings, Dmitry Gutov, 2016/02/05
- Re: "cl-case" with strings, Emanuel Berg, 2016/02/05
- Re: "cl-case" with strings, Dmitry Gutov, 2016/02/05