[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: case or cond
From: |
Pascal J. Bourguignon |
Subject: |
Re: case or cond |
Date: |
Sun, 11 Oct 2009 19:22:17 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) |
Nordlöw <per.nordlow@gmail.com> writes:
> Is case more inefficient than cond?
>
> Does it depend on what kinds of objects that are compared?
Notice that case documentation says that:
Key values are compared by `eql'.
So:
(case expr
(v1 e1)
((v21 ... v2p) e2)
...
(otherwise eo))
is equivalent to:
(let ((e expr))
(cond
((eql e v1) e1)
((memq e '(v21 ... v2p)) e2)
...
(t eo)))
If your cond is not of that form, then it's hardly comparable to case.
On the other hand if it is, then indeed, case might be faster, because
it isn't necessarily implemented as a sequence of tests like cond.
--
__Pascal Bourguignon__