Jump to content

Recommended Posts

Posted

Hi guys,

 

Can someone explain the result behind (eq '(1 2) '(1 2))?

 

I've been using the eq function quite a while and just found this out.

I can very well use equal, but this just rings a concern.

 

Thanks,

Jonathan Handojo

Posted
(equal '(1 2) '( 1 2))

like this ??

 

 

 

 

 

Posted

This will give you a hint

 

(setq a '(1 2) b a)

(eq a b) => T

Posted
4 minutes ago, dlanorh said:

This will give you a hint

 

(setq a '(1 2) b a)

(eq a b) => T

 

Man that's weird... I mean normally if you want to compare between two lists, they are in most cases not gonna be in that form.

 

You normally have a list coming from one evaluation, and another list that evaluates to the exact same list (in my case, it's a list of strings) from another evaluation. Then when I run (eq a b), it evaluates to nil

Posted (edited)

basically with lists (eq ...) tests if they are bound to the same object/entity. Same applies to (= ..). However  (equal ...) tests if they evaluate to the same thing.

Edited by dlanorh
Posted (edited)
7 hours ago, Jonathan Handojo said:

 

Man that's weird... I mean normally if you want to compare between two lists, they are in most cases not gonna be in that form.

 

You normally have a list coming from one evaluation, and another list that evaluates to the exact same list (in my case, it's a list of strings) from another evaluation. Then when I run (eq a b), it evaluates to nil

 

be careful

(setq a '(1 2) b a c a)

(eq a '(1 2) )
;nil
(eq a b)
;T

(equal '(1 2) a )
;T

(= '(1 2) a b)
;nil
(= a b c)
;T

 

Edited by hanhphuc
Jon's dizziness so '(1 2 3) -> '(1 2)
  • Confused 1
Posted
2 hours ago, dlanorh said:

basically with lists (eq ...) tests if they are bound to the same object/entity. Same applies to (= ..). However  (equal ...) tests if they evaluate to the same thing.

Makes sense now, although (eq 2 2) or (eq "str" "str") returns T.

 

2 hours ago, hanhphuc said:

 

be careful


(setq a '(1 2 3) b a c a)

(eq a '(1 2 3) )
;nil
(eq a b)
;T

(equal '(1 2 3) a )
;T

(= '(1 2 3) a b)
;nil
(= a b c)
;T

 

 

Oh, please don't make me any dizzier than I already am 🤣

  • Funny 1
Posted
Just now, Jonathan Handojo said:

Makes sense now, although (eq 2 2) or (eq "str" "str") returns T.

 

 

I know, but 2, "str"  and any real numbers are not lists and so are evaluated.

  • Like 1
Posted

(eq expression 1 expression 2)
It mainly determines whether the two expressions have the same constraint conditions (whether Expression 1 and Expression 2 are set to the same object.

(setq f1 '(a b c) f2 '(a b c))
(setq f3 f2)
(eq f1 f2)   ;---->nil ,Because f1 and f2 have the same value, they do not point to the same list
(eq f3 f2)   ;---->T,Because f3 and f2 point to the same list

So I will tell you this, you should be able to understand it. In the case of not sure whether it is the same table, I generally use (equal expression 1 expression 2 [FUZZ])

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...