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

From: dyb_at_cs.indiana.edu <dyb>
Date: Mon Oct 2 23:12:52 2006

Shiro Kawai <shiro_at_lava.net> 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.

I may be misinterpreting what you mean by "miss it", but this example
isn't valid in R5RS, so it's not something that used to be portable but no
longer is. In fact, it now has a portable semantics (though probably not
the one you want), where it had none before.

To be precise, map requires list arguments, and lists in R5RS "have finite
length and are terminated by the empty list". In R5RS terminology, "it is
an error" to pass map a cyclic list. This means that the behavior is
unspecified, so even if the program does what one wants (whatever that is)
in one's favorite Scheme implementation, it isn't guaranteed to do so in
any other implementation.

The R6RS editors opted to require cycle checks and many other checks (in
safe code) in part to eliminate such portability issues.

Of course, implementors and users are allowed to create nonstandard
libraries, and one such library might define map to allow cyclic lists.

Kent
Received on Mon Oct 02 2006 - 23:12:48 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC