Hi,

I was playing with car, cdr, cons...

I wrote this code:

(defvar *prova* (list 1 2))

(setf (cdr (cdr *prova*)) *prova*)

Now I know that I can't build cyclic lists with this approach. This gave me
an infinite loop, and filled up my RAM and swap.

But I don't understand why. Why can't I tell to the last cdr (which is NIL)
to point to the first element of the lisp?

Something like this:


   +---------+---------+     +---------+---------+
   |         |         |     |         |         |
   |    /|   |         |     |  ----+  |         |
   |   / |   |         |     |      |  |         |
+--+->   |   |      ---+-----+->    |  |    |    |
|  |     |   |         |     |  +---+  |    |    |
|  |     |   |         |     |  |      |    |    |
|  |   ----- |         |     |  +----  |    |    |
|  +---------+---------+     +---------+----+----+
|                                           |
|                                           |
|                                           |
+-------------------------------------------+


Am I completely wrong with this schema? I thought the cdr of and an element
of a list  was the "memory address" of the next element (well, in fact this
is no sense with garbage collection...), and that the list (2) returned by a
code like (cdr (list 1 2)) was just the the interpretation of the memory
address... something like "the value of (cdr (list 1 2)) is a pointer to a
list, SO I show you a list".

Thanks,

Francesco

-- 
Linux Registered User: #414858

P Funking Band
http://www.perugiafunkingband.it
http://www.myspace.com/perugiafunkingband
_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners

Reply via email to