I've just started learning lisp, and I've encountered my first doubt: it's regarding EQ.
I undertand that, as lisp implementations have the freedom to make copies of numbers and characters at any time, you cannot assume, for instance, that (eq 3 3) will be true, as yo cannot assume the first object is the same object as the second, and not just a copy. Please correct me if I understood wrong.
On the other hand, I have made this test:
Finally, in case my last assumption is right, I also assume that implementations should have the freedom to do this (creating pointers to the same object), or not (creating two different objects with the same value). In that case, you couldn't make any assumption about the (eq a b) result.
Am I too lost?
Thanks,
Pep.
I undertand that, as lisp implementations have the freedom to make copies of numbers and characters at any time, you cannot assume, for instance, that (eq 3 3) will be true, as yo cannot assume the first object is the same object as the second, and not just a copy. Please correct me if I understood wrong.
On the other hand, I have made this test:
(setq a 5)
(setq b 5)
(eq a b)
T
In returning true, EQ is actually saying that 'a' is the same object as 'b'. Due to my C/C++ background I feel that then, 'a' and 'b' must be pointers to the same object '5', meaning that they have not only the same value, but they are the same very object, pointed to by two different variables (pointers). Once more, please correct me if I'm wrong.Finally, in case my last assumption is right, I also assume that implementations should have the freedom to do this (creating pointers to the same object), or not (creating two different objects with the same value). In that case, you couldn't make any assumption about the (eq a b) result.
Am I too lost?
Thanks,
Pep.