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: Sat, 21 Aug 2021 12:04:08 +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 09:25]:
> Jean Louis wrote:
> 
> > How I understand it, it is good also for comparison of
> > symbols as strings.
> >
> > (setq s1 "Jane") -> "Jane"
> > (setq s2 "Jane") -> "Jane"
> > (setq s3 "Doe") -> "Doe"
> >
> > Then this is how I understand the intended purpose:
> >
> > (string= s1 s2) -> t
> > (string= s1 s3) -> nil
> 
> Uhm, but in that case, s1, s2, and s3 are evaluated to their
> string values, so at the time of `string=', that's
> 
>   (string= "Jane" "Jane") ; t
>   (string= "Jane" "Doe" ) ; nil

Yes, that is what I meant. It is good to compare symbols which are
possibly strings if they are equal to each other.

(setq s1 1) ⇒ 1
(setq s2 "1") ⇒ "1"

Which is also good to show the error if one of symbols is not string:

(string= s1 s2) eval: Wrong type argument: stringp, 1

> > And of course you are free to compare empty symbols:
> >
> > (string= 'hi 'hi) -> t
> 
> With symbols their "print names" are used, you can get that
> with
> 
>   (symbol-name 'hi) ; "hi"
> 
> So that's virtually (string= "hi" "hi") only here it is done
> _by_ and not before string= (as 'hi does not evaluate to the
> string "hi", for example).

That I don't understand, what I know is that `string=' will evaluate
symbols as strings and compare them, interesting is it will accept
`nil' as value:

(setq s1 "1") ⇒ "1"
(setq s2 "1") ⇒ "1"

(string= s1 s2) ⇒ t

(setq s1 "1") ⇒ "1"
(setq s2 nil) ⇒ nil

(string= s1 s2) ⇒ nil


-- 
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]