[r6rs-discuss] [Formal] Requirement to detect circular lists
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
Received on Mon Oct 02 2006 - 07:30:09 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:00 UTC