help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `compare-strings' style question


From: Barry Margolin
Subject: Re: `compare-strings' style question
Date: Thu, 19 Nov 2009 15:54:20 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <87einuij59.fsf@lola.goethe.zz>, David Kastrup <dak@gnu.org> 
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 ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]