unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* case or cond
@ 2009-10-10 10:03 Nordlöw
  2009-10-11 17:22 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 3+ messages in thread
From: Nordlöw @ 2009-10-10 10:03 UTC (permalink / raw)
  To: help-gnu-emacs

Is case more inefficient than cond?

Does it depend on what kinds of objects that are compared?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* case or cond
@ 2009-10-10 10:03 Nordlöw
  0 siblings, 0 replies; 3+ messages in thread
From: Nordlöw @ 2009-10-10 10:03 UTC (permalink / raw)
  To: help-gnu-emacs

Is case more inefficient than cond?

Does it depend on what kinds of objects that are compared?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: case or cond
  2009-10-10 10:03 case or cond Nordlöw
@ 2009-10-11 17:22 ` Pascal J. Bourguignon
  0 siblings, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2009-10-11 17:22 UTC (permalink / raw)
  To: help-gnu-emacs

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__


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-11 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-10 10:03 case or cond Nordlöw
2009-10-11 17:22 ` Pascal J. Bourguignon
  -- strict thread matches above, loose matches on Subject: below --
2009-10-10 10:03 Nordlöw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).