Jonathan Handojo Posted April 2, 2020 Posted April 2, 2020 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 Quote
dlanorh Posted April 2, 2020 Posted April 2, 2020 This will give you a hint (setq a '(1 2) b a) (eq a b) => T Quote
Jonathan Handojo Posted April 2, 2020 Author Posted April 2, 2020 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 Quote
dlanorh Posted April 2, 2020 Posted April 2, 2020 (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 April 2, 2020 by dlanorh Quote
hanhphuc Posted April 2, 2020 Posted April 2, 2020 (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 April 2, 2020 by hanhphuc Jon's dizziness so '(1 2 3) -> '(1 2) 1 Quote
Jonathan Handojo Posted April 2, 2020 Author Posted April 2, 2020 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 1 Quote
dlanorh Posted April 2, 2020 Posted April 2, 2020 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. 1 Quote
myloveflyer Posted April 3, 2020 Posted April 3, 2020 (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]) 1 Quote
Recommended Posts
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.