Re: Where do two linked lists merge?



cri@xxxxxxxx (Richard Harter) writes:

It was well into the last century when I last took a serious look
at lisp. Can you generate a circular list in lisp without using
the special # markers? In procedural languages it is trivial;
IIRC it shouldn't normally be possible, but what do I know?

Common Lisp is not purely functional, and it is easy enough
to alter the end of a list to point back to the beginning:

(let ((circular-list (list 'rock 'paper 'scissors)))
;; Make the list circular.
(nconc circular-list circular-list)
;; Display it in two ways, with a newline in between.
(with-standard-io-syntax
(write circular-list :circle t)
(terpri)
(write circular-list :readably nil :length 10))
;; Return no values to the read-eval-print loop.
;; WRITE returns the object written; if it were passed through here,
;; the REPL would attempt to print it again, and might end up in an
;; infinite loop.
(values))

The output is:

#1=(ROCK PAPER SCISSORS . #1#)
(ROCK PAPER SCISSORS ROCK PAPER SCISSORS ROCK PAPER SCISSORS ROCK ...)

If you want to try things out, Franz offers a Lisp prompt via Telnet:
http://www.franz.com/products/allegrocl/prompt/
telnet:prompt.franz.com
.