From: sacramento
Subject: circular lisp
Date: 
Message-ID: <48d74abc.0405310753.164fb225@posting.google.com>
Can you give me an example of a circular list in lisp please? How can I create it?

thank you

From: Damien Diederen
Subject: Re: circular lisp
Date: 
Message-ID: <87d64k4jh7.fsf@swing.be>
···········@yahoo.it (sacramento) writes:

Hello,

> Can you give me an example of a circular list in lisp please? How
> can I create it?

A circular list can only be created by mutation:

| (let ((*print-circle* t)
|       (list (copy-list '(1 2 3))))
|   (setf (cdr (last list)) list)
|   (format t "; ~A~%" list))

=> ; List: #1=(1 2 3 . #1#)

This code modifies the CDR of the last cons of LIST to point back to
the beginning. It binds *PRINT-CIRCLE* to T to avoid an infinite loop
in the formatter.

You can also create circular lists as literals (mutation is still
necessary, but it is performed by the lisp reader) using the
"backreferencing" syntax shown above:

| (nth 1000 '#1=(1 2 3 . #1#))

=> 2

> thank you

Cu,
Dash.

-- 
Le pouvoir des médias supprime les raisonnements fondamentaux de la société
du spectacle.
	-- Source : http://www.lillepop.org/fun/logomachie.html
-- 
http://users.swing.be/diederen/
From: Martti Halminen
Subject: Re: circular lisp
Date: 
Message-ID: <pan.2004.05.31.16.45.19.542564@kolumbus.fi>
On Mon, 31 May 2004 08:53:51 -0700, sacramento wrote:

> Can you give me an example of a circular list in lisp please? How can I create it?

USER(2): (setq *print-circle* t)
T
USER(3): (setq aa (list 1 2 3))
(1 2 3)
USER(4): (last aa)
(3)
USER(5): (setf (cdr (last aa)) aa)
#1=(1 2 3 . #1#)

-- 
From: Thomas A. Russ
Subject: Re: circular lisp
Date: 
Message-ID: <ymioeo3ql2n.fsf@sevak.isi.edu>
···········@yahoo.it (sacramento) writes:

> 
> Can you give me an example of a circular list in lisp please? How can I create it?

'#1=(a b c . #1#)

Be sure to either set *print-circle* to T or *print-length* to some
integer first, though.

-- 
Thomas A. Russ,  USC/Information Sciences Institute