all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is there any difference between `equal' and `string=' for strings?
@ 2021-08-19  4:56 Marcin Borkowski
  2021-08-19  6:21 ` Jean Louis
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Marcin Borkowski @ 2021-08-19  4:56 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Well, of course a string and a symbol can never be `equal', but they can
be `string='.  But what if both arguments are strings?  The docstrings
seem to imply that you can use `equal' and `string=' interchangeably and
they will always give the exact same result.  Is that correct?

TIA,

-- 
Marcin Borkowski
http://mbork.pl



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-19  4:56 Is there any difference between `equal' and `string=' for strings? Marcin Borkowski
@ 2021-08-19  6:21 ` Jean Louis
  2021-08-19 23:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-19 15:35 ` [External] : " Drew Adams
  2021-08-19 23:02 ` Is there any difference between `equal' and `string=' for strings? Emanuel Berg via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-08-19  6:21 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list

* Marcin Borkowski <mbork@mbork.pl> [2021-08-19 07:57]:
> Well, of course a string and a symbol can never be `equal', but they can
> be `string='.  But what if both arguments are strings?  The docstrings
> seem to imply that you can use `equal' and `string=' interchangeably and
> they will always give the exact same result.  Is that correct?

(string-equal 123 "123") -- gives error, as string= is alias for
string-equal that is to handle exclusively strings.

(equalp 123 "123") -- does not give error.

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


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* RE: [External] : Is there any difference between `equal' and `string=' for strings?
  2021-08-19  4:56 Is there any difference between `equal' and `string=' for strings? Marcin Borkowski
  2021-08-19  6:21 ` Jean Louis
@ 2021-08-19 15:35 ` Drew Adams
  2021-08-21  3:43   ` this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?) Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-19 23:02 ` Is there any difference between `equal' and `string=' for strings? Emanuel Berg via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2021-08-19 15:35 UTC (permalink / raw)
  To: Marcin Borkowski, Help Gnu Emacs mailing list

> Well, of course a string and a symbol can never be `equal', but they can
> be `string='.  But what if both arguments are strings?  The docstrings
> seem to imply that you can use `equal' and `string=' interchangeably and
> they will always give the exact same result.  Is that correct?

If both args are strings those predicates always give the same result.

`equal' is not costly for simple things that can also
be compared with, say `eq' or `string='.  It's costly
for things like complex list structure.  But when you
need `equal' you need `equal'. ;-)



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-19  4:56 Is there any difference between `equal' and `string=' for strings? Marcin Borkowski
  2021-08-19  6:21 ` Jean Louis
  2021-08-19 15:35 ` [External] : " Drew Adams
@ 2021-08-19 23:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20  5:25   ` Jean Louis
  2 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-19 23:02 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski wrote:

> Well, of course a string and a symbol can never be `equal',
> but they can be `string='. But what if both arguments
> are strings?

... and if both arguments are symbols?

(string= 'hi 'hi) ; t

(Why ever one would use `string=' for that.)

Yeah, it is a jungle all that ...

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-19  6:21 ` Jean Louis
@ 2021-08-19 23:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20  5:35     ` Jean Louis
  0 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-19 23:14 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-19 23:02 ` Is there any difference between `equal' and `string=' for strings? Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-20  5:25   ` Jean Louis
  2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-24 14:55     ` Marcin Borkowski
  0 siblings, 2 replies; 28+ messages in thread
From: Jean Louis @ 2021-08-20  5:25 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-08-20 02:04]:
> Marcin Borkowski wrote:
> 
> > Well, of course a string and a symbol can never be `equal',
> > but they can be `string='. But what if both arguments
> > are strings?
> 
> ... and if both arguments are symbols?
> 
> (string= 'hi 'hi) ; t
> 
> (Why ever one would use `string=' for that.)
> 
> Yeah, it is a jungle all that ...

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

And of course you are free to compare empty symbols:

(string= 'hi 'hi) ⇒ t

However by looking at the purpose it becomes all logical to me.


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-19 23:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-20  5:35     ` Jean Louis
  2021-08-20  6:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-08-20  5:35 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  5:25   ` Jean Louis
@ 2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  9:04       ` Jean Louis
  2021-08-24 14:55     ` Marcin Borkowski
  1 sibling, 2 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-20  6:24 UTC (permalink / raw)
  To: help-gnu-emacs

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

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

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  5:35     ` Jean Louis
@ 2021-08-20  6:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  9:05         ` Jean Louis
  0 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-20  6:32 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> `cl-equalp' I give up ;)
>
> equalp is very handy.

The docstring says

  This is like ‘equal’, except that it accepts numerically
  equal numbers of different types (float vs. integer), and
  also compares strings case-insensitively.

Just so many to keep track of ...

Also `eql' which works like `eq' only also "works" for
floats ...

  (eq  1   1  )  ; t
  (eq  1.0 1.0)  ; nil

  (eql 1   1  )  ; t
  (eql 1.0 1.0)  ; t

  (eql -0.0 0.0) ; nil (uhm, how does that situation appear?)
  
  (*   -1   0.0) ; -0.0 (okay ...)

  (=   -0.0 0.0) ; t (the same position on the axis of real numbers)

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20 23:12         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  9:08         ` Jean Louis
  2021-08-21  9:04       ` Jean Louis
  1 sibling, 2 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-20  6:41 UTC (permalink / raw)
  To: help-gnu-emacs

>> (string= 'hi 'hi) -> t
>
> With symbols their "print names" are used, you can get that
> with
>
>   (symbol-name 'hi) ; "hi"

The reason for this, I think, is for example so one can do
a `defun' like this

  (defun do-something (method)
    (when (string= method "now")
      (message "I'm all over it") ))

Then one can do either

  (do-something "now")

or

  (do-something 'now)

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-20 23:12         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20 23:42           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  9:08         ` Jean Louis
  1 sibling, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-20 23:12 UTC (permalink / raw)
  To: help-gnu-emacs

>   (defun do-something (method)
>     (when (string= method "now")
>       (message "I'm all over it") ))

What about

(defun get-string (s)
  (if (stringp s)
      s
    (let ((val (symbol-value s)))
      (or (and (stringp val) val)
          (symbol-name s) ))))

(defun string== (s1 s2)
  (string= (get-string s1)
           (get-string s2) ))

(defvar one)
(setq one nil)
(string== "one" "one") ; t
(string== 'one  "one") ; t

(defvar two)
(setq two "one")
(string== 'two  "one") ; t
(string== two   "one") ; t, confusing

(setq one "two")
(string== one "one") ; nil
; argh ...

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20 23:12         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-20 23:42           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  0:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-20 23:42 UTC (permalink / raw)
  To: help-gnu-emacs

>>   (defun do-something (method)
>>     (when (string= method "now")
>>       (message "I'm all over it") ))
>
> What about
>
> (defun get-string (s)
>   (if (stringp s)
>       s
>     (let ((val (symbol-value s)))
>       (or (and (stringp val) val)
>           (symbol-name s) ))))
>
> (defun string== (s1 s2)
>   (string= (get-string s1)
>            (get-string s2) ))

Maybe one should rationalize everything down into

"same" - same object is t, else nil

"equal-all" - same type _and_ equal data is t, else nil (for
this purpose, the predicates, e.g., `stringp' would imply the
existence of a type)

"equal-data" - equal data, here it would have to be set up on
a case-by-case basis for all the types, so while obviously for
`integerp' and `floatp'

  (equal-data 2 2.0)

but one can think of a lot more, for example

  (equal-data "data" '(?d ?a ?t ?a)) ; t

and so on.

Not saying one should change Lisp tho, just to theorize what
it could be I mean ...

What does the computer science (or perhaps login/math
science?) of "type theory" have to say about all this? :)
No, really?

Did all the equality functions arrive little by little or was
there a plane? A little bit of both perhaps?

All the overlap are implementation/optimization derived
things, right?

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20 23:42           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  0:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  0:30               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21  0:08 UTC (permalink / raw)
  To: help-gnu-emacs

> "equal-all" - same type _and_ equal data is t, else nil (for
> this purpose, the predicates, e.g., `stringp' would imply the
> existence of a type)

How is it with Lisp, it is dynamically typed, right, and the
values, not variables, have type?

But what's the real definition of type?

(type-of 1)         ; integer
(type-of 1.0)       ; float
(type-of t)         ; symbol
(type-of 'type-of)  ; not function, symbol, well, OK
(type-of #'type-of) ; still not function, symbol
(type-of [1 2 3])   ; vector
(type-of "string")  ; string
(type-of ?a)        ; not char, integer, yes
(type-of '(1 2 3))  ; not list, cons
(type-of nil)       ; not list, symbol
(type-of '())       ; same
(type-of (list))    ; ..

... ?

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-21  0:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  0:30               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21  0:30 UTC (permalink / raw)
  To: help-gnu-emacs

> (type-of 'type-of)  ; not function, symbol, well, OK
> (type-of #'type-of) ; still not function, symbol

So functions don't have type, they are symbols with their
`symbol-function' set to some function? Hm, "they" are
symbols ...

Wasn't it SML who had a type inference system so even tho the
formal parameters didn't have explicit type (maybe that was
optional) it could infere the types, and the whole inferred
prototype would be the type of the function?

So for the equivalent of

  (defun add-two-terms (a b)
    (+ a b) )

the inferred type would be (not in SML's notation)

  f(R, R) -> R 

So what happens then, you could have a second function that
would take an argument that had that type, and then that
function would have the type

  f'(f(R, R) -> R , something else) -> ... etc

To have a static type check in Lisp, how would that work, the
functions would come with metadata or publish their interface
somewhere to show for which types they are defined?

Also I remember from SML, Haskell, and Erlang, was the focus
on pattern matching. More of a syntax thing, maybe? Should be
possible in Lisp as well, right?

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-19 15:35 ` [External] : " Drew Adams
@ 2021-08-21  3:43   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
                       ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21  3:43 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

> If both args are strings those predicates always give the
> same result.
>
> `equal' is not costly for simple things that can also be
> compared with, say `eq' or `string='. It's costly for things
> like complex list structure. But when you need `equal' you
> need `equal'. ;-)

If one passes complex list structures as an argument to
a function, how does that happen? Does it happen differently
from other types, maybe just a reference to the `car'?

I've heard of call by reference, call by value and call
by copy.

How does that work in Elisp?

And what if the value is a reference?

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  3:43   ` this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?) Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  4:20       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  5:39     ` FW: " Drew Adams
  2021-08-21  6:50     ` tomas
  2 siblings, 1 reply; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21  3:49 UTC (permalink / raw)
  To: help-gnu-emacs

> If one passes complex list structures as an argument to
> a function, how does that happen? Does it happen differently
> from other types, maybe just a reference to the `car'?

Seems to be different but from function to function rather.

`nconc' (C built-in function)

  Concatenate any number of lists by altering them. Only the
  last argument is not altered, and need not be a list.

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  4:20       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21  4:20 UTC (permalink / raw)
  To: help-gnu-emacs

Another thing with respect to functions and the formal
parameters are that in other languages, e.g. C++, one can do
function overloading where the function names are the same but
the sets of parameters differ, this amounts to two (or more)
functions with distinct "signatures".

I guess one cannot do that (easily) in Lisp since a function
is just a symbol with a set `symbol-function'.

The inferred function types of SML, expressed as mappings, were
sort of cool but the prototypes or signatures of C++ - is that
something they have because, frankly, C++ isn't good enough?

If so, interesting that it brought along the possibility of
overloading ...

Now in Lisp we have arbitrary number of arguments (&rest),
&optional arguments, default values (Common Lisp has, so
`cl-defun' for Elisp/Jean). Hm ... is the unused argument _
a convention, or is it actually impossible to use?

Anyway much better than overloading IMO.

Perhaps because of the dynamic type system it isn't needed?
One can just have one function, find out what types the
arguments are, and branch on that. Perhaps one can do that in
C++ as well in just one function, with pointers, or by
converting the int(eger) to a float ...

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* FW: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  3:43   ` this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?) Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  5:39     ` Drew Adams
  2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  6:50     ` tomas
  2 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2021-08-21  5:39 UTC (permalink / raw)
  To: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'

[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

> I've heard of call by reference, call by value and call
> by copy.  How does that work in Elisp?
> And what if the value is a reference?

Lisp always passes a pointer to a value.  Not
a pointer as such - pointers are not things in
the language.

You don't think of manipulating pointers.
But what's passed is a reference to a value
(a memory location), and that value can be a
number, string, vector, symbol, cons, closure,
hash table,...

What happens corresponds exactly to what your
mental model already is, no doubt, when you
program in Lisp, however you might want to
characterize it.

The most important thing to be aware of is
that when a value is passed as an arg it's
_not copied_.  The value exists somewhere,
and its location is passed.  The function's
formal parameter is bound to (points to) the
existing value.

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13749 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  3:43   ` this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?) Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-21  5:39     ` FW: " Drew Adams
@ 2021-08-21  6:50     ` tomas
  2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 28+ messages in thread
From: tomas @ 2021-08-21  6:50 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 275 bytes --]

On Sat, Aug 21, 2021 at 05:43:06AM +0200, Emanuel Berg via Users list for the GNU Emacs text editor wrote:

[...]

> I've heard of call by reference, call by value and call
> by copy.
> 
> How does that work in Elisp?

call by copy-of-reference ;-P

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  9:04       ` Jean Louis
  2021-08-21 19:09         ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-08-21  9:04 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  6:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  9:05         ` Jean Louis
  2021-08-21 19:14           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-08-21  9:05 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-08-20 09:33]:
> Jean Louis wrote:
> 
> >> `cl-equalp' I give up ;)
> >
> > equalp is very handy.
> 
> The docstring says
> 
>   This is like ‘equal’, except that it accepts numerically
>   equal numbers of different types (float vs. integer), and
>   also compares strings case-insensitively.

I don't know, I use `equalp' in Common Lisp. Not in Emacs Lisp. Though
I may mix it sometimes.


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-08-20 23:12         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-21  9:08         ` Jean Louis
  2021-08-21 19:17           ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 28+ messages in thread
From: Jean Louis @ 2021-08-21  9:08 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-08-20 09:42]:
> >> (string= 'hi 'hi) -> t
> >
> > With symbols their "print names" are used, you can get that
> > with
> >
> >   (symbol-name 'hi) ; "hi"
> 
> The reason for this, I think, is for example so one can do
> a `defun' like this
> 

 (defun do-something (method)
    (when (string= method "now")
     (message "I'm all over it") ))

> Then one can do either
> 
>   (do-something "now")
> 
> or
> 
>   (do-something 'now)

That is something new to me. I would not ever use it that way, but you
discovered it. It looks like incorrect use as (type-of 'now) ⇒ symbol
and is then compared as string.

I would do:

(setq now "Not now") ⇒ "Not now"
(do-something now) ⇒ nil


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-21  9:04       ` Jean Louis
@ 2021-08-21 19:09         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21 19:09 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-21  9:05         ` Jean Louis
@ 2021-08-21 19:14           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21 19:14 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> The docstring says
>> 
>>   This is like ‘equal’, except that it accepts numerically
>>   equal numbers of different types (float vs. integer), and
>>   also compares strings case-insensitively.
>
> I don't know, I use `equalp' in Common Lisp. Not in Emacs
> Lisp. Though I may mix it sometimes.

I don't think so :)

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-21  9:08         ` Jean Louis
@ 2021-08-21 19:17           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21 19:17 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> (defun do-something (method)
>>   (when (string= method "now")
>>    (message "I'm all over it") ))
>>
>> Then one can do either
>> 
>>   (do-something "now")
>> 
>> or
>> 
>>   (do-something 'now)
>
> I would do:
>
> (setq now "Not now") -> "Not now"
> (do-something now) -> nil

:)

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: FW: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  5:39     ` FW: " Drew Adams
@ 2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21 19:41 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

> The most important thing to be aware of is that when a value
> is passed as an arg it's _not copied_. The value exists
> somewhere, and its location is passed. The function's formal
> parameter is bound to (points to) the existing value.

OK, cool.

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?)
  2021-08-21  6:50     ` tomas
@ 2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 28+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-08-21 19:41 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

>> I've heard of call by reference, call by value and call
>> by copy.
>> 
>> How does that work in Elisp?
>
> call by copy-of-reference ;-P

100

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




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: Is there any difference between `equal' and `string=' for strings?
  2021-08-20  5:25   ` Jean Louis
  2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-08-24 14:55     ` Marcin Borkowski
  1 sibling, 0 replies; 28+ messages in thread
From: Marcin Borkowski @ 2021-08-24 14:55 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs


On 2021-08-20, at 07:25, Jean Louis <bugs@gnu.support> wrote:

> * Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-08-20 02:04]:
>> Marcin Borkowski wrote:
>> 
>> > Well, of course a string and a symbol can never be `equal',
>> > but they can be `string='. But what if both arguments
>> > are strings?
>> 
>> ... and if both arguments are symbols?
>> 
>> (string= 'hi 'hi) ; t
>> 
>> (Why ever one would use `string=' for that.)
>> 
>> Yeah, it is a jungle all that ...
>
> 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
>
> And of course you are free to compare empty symbols:
>
> (string= 'hi 'hi) ⇒ t
>
> However by looking at the purpose it becomes all logical to me.

It can even do (string= "hello" 'hello) => t
(Why could that be useful, I'm not sure.)

-- 
Marcin Borkowski
http://mbork.pl



^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-08-24 14:55 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-19  4:56 Is there any difference between `equal' and `string=' for strings? Marcin Borkowski
2021-08-19  6:21 ` Jean Louis
2021-08-19 23:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-20  5:35     ` Jean Louis
2021-08-20  6:32       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  9:05         ` Jean Louis
2021-08-21 19:14           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-19 15:35 ` [External] : " Drew Adams
2021-08-21  3:43   ` this is United States calling (was: Re: [External] : Is there any difference between `equal' and `string=' for strings?) Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  3:49     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  4:20       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  5:39     ` FW: " Drew Adams
2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  6:50     ` tomas
2021-08-21 19:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-19 23:02 ` Is there any difference between `equal' and `string=' for strings? Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-20  5:25   ` Jean Louis
2021-08-20  6:24     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-20  6:41       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-20 23:12         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-20 23:42           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  0:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  0:30               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  9:08         ` Jean Louis
2021-08-21 19:17           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-21  9:04       ` Jean Louis
2021-08-21 19:09         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-08-24 14:55     ` Marcin Borkowski

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.