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: Fri, 20 Aug 2021 01:14:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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?

Anyway careful with `equalp' for strings, note that

  (cl-equalp "Hi" "hi") ; t

but

  (string= "Hi" "hi") ; nil

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

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




reply via email to

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