[r6rs-discuss] [Formal] Requirement to detect circular lists

Dan Muresan dan-r6rs at omnigia.com
Tue Oct 3 05:38:27 EDT 2006


> Right?  I sure hope this qualifies as more elegant.

OK, Andre's program has problems. I really liked Shiro's example though --
for reference, here it is:

  (let ((x (list 1 2)))
    (set-cdr! (cdr x) x)   ;; x = #0=(1 2 . #0#)
    (map f some-list x))

It's a very efficient way to create lazy periodic infinite lists, used for
alternating actions in (map). Other uses are possible too.

Shiro, I wouldn't say it's a poor man's tool. Scheme has lazy lists, both
using force/delay and using SRFI-45. As SRFI-45 points out, force/delay
lazy lists can create space leaks. So in the end, circular lists seem
easier to create, more efficient, and potentially safer *for the periodic
case*.


Dan Muresan
http://alumnus.caltech.edu/~muresan



More information about the r6rs-discuss mailing list