From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: Lisp: Functions for multiple comparisons Date: 21 Nov 2002 20:56:24 +0100 Organization: informatimago.com Sender: help-gnu-emacs-admin@gnu.org Message-ID: <87lm3melxz.fsf@thalassa.informatimago.com> References: <5l3cpvj13t.fsf@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1037909170 15191 80.91.224.249 (21 Nov 2002 20:06:10 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 21 Nov 2002 20:06:10 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18ExaR-0003wd-00 for ; Thu, 21 Nov 2002 21:06:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18ExW4-0002fs-00; Thu, 21 Nov 2002 15:01:36 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: thalassa.informatimago.com (212.87.205.57) Original-X-Trace: fu-berlin.de 1037908587 20077905 212.87.205.57 (16 [41911]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Xref: shelby.stanford.edu gnu.emacs.help:107287 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:3842 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:3842 "Stefan Monnier " writes: > >>>>> "Greg" == Greg Hill 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 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