[r6rs-discuss] [Formal] Requirement to detect circular lists
AndrevanTonder
andre at het.brown.edu
Mon Oct 2 07:30:09 EDT 2006
On Sun, 1 Oct 2006, Shiro Kawai wrote:
> According to the note on 'map' in section 23.3.1, page 124
> must the r6rs compliant system raise an exception in the
> following code?
>
> (let ((x (list 1 2)))
> (set-cdr! (cdr x) x) ;; x = #0=(1 2 . #0#)
> (map f some-list x))
>
> This may be a kluge, but sometimes it is handy and I'd miss it
> if R6RS won't allow it.
You are right that it would be disallowed, as would many other useful programs
using infinite lists. Not only map is affected, but also filter, memp, ....
Here is another useful program that would be illegal under r6rs:
(define threes (list 1))
(set-cdr! threes threes)
(define (smallest-multiple-larger-than-10 k)
(let ((sum 0))
(lambda (x)
(set! sum (+ sum x))
(when (> sum 10)
(k sum)))))
(call/cc (lambda (break)
(map (smallest-multiple-larger-than-10 break) threes)))
Andre
More information about the r6rs-discuss
mailing list