This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

eq eql at work...

3 posts · 2371 views

HI
I have a query about that functions..
for ex. if I build a list:
(setf x ' (a b c))
and after I set : (setf y x)
now x and y are two different pointers to the same object in memory (like in Python's behavior...), is it?
infact : (eq x y) -> TRUE like (eql x y) t...(ps I know that two objects are eq if they are actually the same object in memory with same value;
but if i use push. : (push 'd x), only x changes not y!...then I can suppose that it's not a change_in_place...but a new list is create!!..right??

But if after use pop : (pop x) -> x returns now to have the same value of y but I suppose that now they are different object in memory, because also pop create a new list:
(let ((x (car 1st)))
   (setf 1st (cdr 1st))
   x)
but if now i try to compare the two list : (eq x y) I would expect NIL but T happens...then NOW I'm confusing about eq & eql...
sorry for my bad english and thanks in advance for help !!!

Re: eq eql at work...

push and pop are actually macroes:
(macroexpand-1 '(push 'd x)) ==>
(SETQ X (CONS 'D X)) ;

(macroexpand '(pop x)) ==>
(LET ((TMP-1 (CAR X))) 
    (SETQ X (CDR X)) 
    TMP-1) 
As you suspected CL doesn't change the target but makes a new list and associate X with that instead.
Y still points to the same value that X once pointed to and that is still a part of X.
Thus this is eq:
(eq (cdr x) y) ==>
T
pop associated x with (cdr x) and thus it again points to the same location in memory as y do.
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p

Re: eq eql at work...

Thanks sylwester !!
now it's clear :!: