Hi,

Francesco Petrogalli <[email protected]> writes:

> 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.

The reason for this isn't the operation you were performing, but your
lisp implementation trying to print this circular list.  Your analysis
of the datastructure was absolutly correct.

Do

(setf *print-circle* t)

and try again.  This will make the printer check for circularities, and
your list gets printed like this: #1=(1 2 . #1#)

HTH
Albert

>
> 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
_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners

Reply via email to