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

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

Re: Is there any difference between `equal' and `string=' for strings?


From: Jean Louis
Subject: Re: Is there any difference between `equal' and `string=' for strings?
Date: Fri, 20 Aug 2021 08:35:33 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2021-08-20 02:16]:
> Jean Louis wrote:
> 
> > (string-equal 123 "123") -- gives error, as string= is alias
> > for string-equal that is to handle exclusively strings.
> 
> Nope, you can pass symbols as well:
> 
>   (string= "hi" "hi") ; t
>   (string= 'hi  "hi") ; t
>   (string= 'hi  'hi ) ; t
> 
> > (equalp 123 "123")
> 
> `equalp'? Aren't you the one who doesn't like Elisp CL?

You eagle eye! 

I really did not notice it. Maybe it is due to Common Lisp handy
habit. I have (almost) no "equalp" in my Emacs Lisp, just in comments.

> Anyway careful with `equalp' for strings, note that
> 
>   (cl-equalp "Hi" "hi") ; t

On the other hand that is handy when testing for file extensions like
.jpg and .JPG otherwise I downcase it all before the test.

> > Sometimes program outputs different types, could be `nil' or
> > `string' and those outputs maybe need to be expected as any
> > type or as exclusively strings. That is where the difference
> > comes handy, as sometimes I do want to get error report.
> > If I wish to test strings I better use `string='
> 
> It is a jungle, the rule of thumb I think is
> 
>   `eq' to answer the question "is it the same Lisp object"?
> 
>   `=' to compare numbers in the math sense
>   
>   `string=' for strings only
> 
>   `equal' for everything else, except ...
> 
>   `cl-equalp' I give up ;)

Equalp is very handy.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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