eq eql at work...

Discussion of Common Lisp

eq eql at work...

Postby megera » Mon Oct 15, 2012 7:39 am

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:
Code: Select all
(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 !!!
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm

Re: eq eql at work...

Postby sylwester » Mon Oct 15, 2012 11:39 am

push and pop are actually macroes:
Code: Select all
(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:
Code: Select all
(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
sylwester
 
Posts: 83
Joined: Mon Jul 11, 2011 2:53 pm

Re: eq eql at work...

Postby megera » Mon Oct 15, 2012 12:24 pm

Thanks sylwester !!
now it's clear :!:
megera
 
Posts: 30
Joined: Wed Oct 10, 2012 1:34 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 7 guests

cron