Adding to @molbdnilo answer most scheme imeplemetation define delay
and force
,
that allow to create so called streams (defined in
SICP).
; The infinite list (1 1 1 ...
(define ones (cons 1 (delay ones)))
> ones
(1 . #<promise>)
> (force (cdr ones))
(1 . #<promise>)
(eq? ones (force (cdr ones)))
#t
delay
and force
can be implemented as macros that are just lambda expression. You can even write procedures like filter or map that handle streams.
EDIT:
Also defined by R7RS you can create real circular list with datum labels.
(define x '#0=(a b c . #0#))
x
;; ==> #0=(a b c . #0#)
(eq? x (cdddr x))
#t
If Scheme fully support the R7RS spec it should allow to define and display circular list in the same way. Note that in Kawa Scheme it will print in a loop to display the circular list you need to use (write x)
.