From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: Lisp: Functions for multiple comparisons
Date: 21 Nov 2002 20:56:24 +0100 [thread overview]
Message-ID: <87lm3melxz.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 5l3cpvj13t.fsf@rum.cs.yale.edu
"Stefan Monnier <foo@acm.com>" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:
> >>>>> "Greg" == Greg Hill <ghill@synergymicro.com> writes:
> > (meq (char-syntax (following-char)) ?w ?_)
> > instead of using
> > (memq (char-syntax (following-char) '(?w ?_)))
>
> memq is pretty fast given the general slowness of the elisp interpreter.
> If you really care about the few extra chars, then you can of course do
>
> (defun meq (x &rest xs) (memq x xs))
>
> although I honestly don't see the point.
>
>
> Stefan
Perhaps avoiding cutting too much:
Greg Hill <ghill@synergymicro.com> writes:
> I am aware of the built-in functions memq and member. But what I
> really want is a pair of special forms that work more like 'or and
> 'and. The first argument would be compared against all of the rest
> using either 'eq or 'equal, returning 't if any match was found.
So, Greg wants a special form like 'or or 'and. That is, with lazy
evaluation of the remaining arguments!
(defmacro meq (key &rest values)
`(let ((meq_key ,key)
(meq_values ',values))
(while (and meq_values (not (eq meq_key (eval (car meq_values)))))
(setq meq_values (cdr meq_values)))
meq_values))
(show (macroexpand (quote (meq 12 (+ 9 1) (+ 10 2) (length (make-vector 1e9)) 13))))
==> (let ((meq_key 12) (meq_values (quote ((+ 9 1) (+ 10 2) (length (make-vector 1000000000.0)) 13)))) (while (and meq_values (not (eq meq_key (eval (car meq_values))))) (setq meq_values (cdr meq_values))) meq_values)
(show (meq 12 (+ 9 1) (+ 10 2) (length (make-vector 1e9)) 13))
==> ((+ 10 2) (length (make-vector 1000000000.0)) 13)
But of course, it you only use lists of constants like '(?w ?_), it's
better to use memq which is a primitive.
> For example, a special form using an 'eq comarison might be named 'meq
> and be called like:
>
> (meq (char-syntax (following-char)) ?w ?_)
>
> instead of using
>
> (memq (char-syntax (following-char) '(?w ?_)))
> or
> (or (eq (char-syntax (following-char)) ?w) (eq (char-syntax
> (following-char)) ?_))
> or
> (let ((syntax (char-syntax (following-char)))) (or (eq syntax ?w)
> (eq syntax ?_)))
>
> Is there already something like that that I simply am not yet aware
> of? If not, am I wrong in thinking that the kind of special forms I
> am imagining would be computationally more efficient than any of the
> alternatives shown above?
>
> --Greg
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
next prev parent reply other threads:[~2002-11-21 19:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1035590178.16479.help-gnu-emacs@gnu.org>
2002-10-26 3:26 ` please explain diff bet. K&R and Linux c-mode styles Matt Armstrong
2002-10-29 0:37 ` seberino
2002-10-29 13:28 ` Kevin Dziulko
2002-10-29 13:55 ` Alfred M. Szmidt
[not found] ` <mailman.1035851913.4061.help-gnu-emacs@gnu.org>
2002-10-29 2:33 ` Edgar Antonio Luna Díaz
2002-11-15 2:54 ` Emacs Lisp: Problem with nested condition-case and catch in byte compiled code Greg Hill
2002-11-15 18:22 ` Greg Hill
[not found] ` <mailman.1037661783.25741.help-gnu-emacs@gnu.org>
2002-11-19 0:08 ` Stefan Monnier <foo@acm.com>
2002-11-19 2:47 ` Greg Hill
2002-11-20 21:14 ` Lisp: Functions for multiple comparisons Greg Hill
[not found] ` <mailman.1037827276.893.help-gnu-emacs@gnu.org>
2002-11-20 23:03 ` Stefan Monnier <foo@acm.com>
2002-11-21 19:56 ` Pascal Bourguignon [this message]
2002-11-27 19:07 ` Index of element in a sequence Greg Hill
[not found] ` <mailman.1038424169.3933.help-gnu-emacs@gnu.org>
2002-11-27 19:23 ` Barry Margolin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lm3melxz.fsf@thalassa.informatimago.com \
--to=pjb@informatimago.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.