From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: `compare-strings' style question Date: Thu, 19 Nov 2009 15:54:20 -0500 Organization: A noiseless patient Spider Message-ID: References: <878we2kakq.fsf@lola.goethe.zz> <87einuij59.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1258666855 9350 80.91.229.12 (19 Nov 2009 21:40:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Nov 2009 21:40:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 19 22:40:49 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NBEkC-0001hO-3N for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 22:40:48 +0100 Original-Received: from localhost ([127.0.0.1]:38785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBEkB-0008FN-D9 for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 16:40:47 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!goblin1!goblin.stu.neva.ru!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-X-Trace: news.eternal-september.org U2FsdGVkX18QkRtQLyOf2F1HjScbwdmd4P6280pyVcYQyivrg407NtMkGPfqVF41E6yUwN2fztPtRqbG3brv+67/RKOli3RK7J0S+eURtKEVQ88y06k9xgCPcAE8ZbsmhP78keVmQJM= Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Thu, 19 Nov 2009 20:54:20 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Auth-Sender: U2FsdGVkX18L5c5uBponXecmCQhOC5oiH/04pnUZT3Y= Cancel-Lock: sha1:weDbOLFLjQMqUKEofrBEaiyXeAQ= Original-Xref: news.stanford.edu gnu.emacs.help:174874 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69947 Archived-At: In article <87einuij59.fsf@lola.goethe.zz>, David Kastrup wrote: > tomas@tuxteam.de writes: > > > On Thu, Nov 19, 2009 at 12:39:33PM +0100, David Kastrup wrote: > >> tomas@tuxteam.de writes: > >> > >> > Hi, > >> > > >> > In Elisp, I'm trying to test whether a string is a prefix of another. > > > > [...] > > > >> > (when (eq (compare-strings foo 0 5 bar 0 5) t) > >> > ...) > >> > > >> > which looks rather funny. My question: are there better idioms? Am I > >> > barking up the wrong function? > >> > >> (unless (numberp ... > >> > >> or > >> > >> (if (symbolp ... > > > > Thanks. Still looks a bit funna, though :-) > > In my opinion, t was the wrong choice for a match. nil would have been > much better because you can't use the result of compare-strings as a > condition. > > But I suppose there is not much one can do now because of compatibility. That would still be weird, because (not (compare-strings ...)) would be the way to tell if they're equivalent. C has the same problem with its strcmp() function, which returns negative, 0, or positive, where 0 is C's falsehood. The basic problem is that IF is designed to work with binary predicates, and this operation is trinary. Maybe compare-strings should have been defined like strcmp, returning 0 for the middle case. Then you wouldn't be tempted to think of it as a predicate. (zerop (compare-strings ...)) doesn't seem as weird as (not (compare-strings ...)). -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***