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: Emanuel Berg
Subject: Re: Is there any difference between `equal' and `string=' for strings?
Date: Sat, 21 Aug 2021 21:09:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

> 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

Yes, but what you are passing here are not symbols but their
_values_, however can can pass literally a symbol as well in
which case that symbol's print name, i.e. its `symbol-name',
is used. So for example

  (symbol-name 'hi)  ; "hi"
  (string= 'hi "hi") ; t

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

It seems that you understand? `string=' uses, or could use at
least, `symbol-name' to get the symbols print name.

(let ((sym 'hi)
      (str "hi") )
  (when (and (symbolp sym)
             (stringp str) )
    (list (string= (symbol-name sym) str)
          (string= sym str) ))) ; (t t)

(PS, why don't string= take &rest like `='? OTOH string= is an
 alias for `string-equal' and `equal' don't take &rest either
 ...)

> and compare them, interesting is
> it will accept `nil' as value:

Because nil is a symbol:

  (symbolp nil) ; t
  (symbol-name nil) ; "nil"

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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