(let ((x 10))
(display "the result is: ")
(display x)
(define x 42))
(newline))
; SRFI 245: the result is 10
; SRFI 251: <it is an error>
According to this proposal, the result got to be 10 --
the equivalent R7RS body is nested as follows:
(let ((x 10))
(display "the result is: ")
(display x)
(let ()
(define x 42)
(newline)))
SRFI-245, as I understand it, proposes different "translation":
(let ((x 10))
(define x
(begin
(display "the result is: ")
(display x)
42))
(newline))
... which "is an error" according to R7RS, giving an implementation
a lot of options on how to react (strictly speaking, printing 10 is
one of the options)
On Friday, December 1, 2023 8:54:24 PM (-05:00), Per Bothner wrote:
> Also consider:
>
> (let ((x 10))
> (display "the result is: ")
> (display x)
> (define x 42))
> (newline))
>
> I believe the result here should be undefined - but *not* 10.
>
> In Kawa (which implements 245 and does some flow analysis) you get:
> the result is: 42
> Howver, if you replaced '42' by the non-constant '(list 42)' you get:
> the result is: #!undefined
> In both cases you get a compile-time warning:
> x.scm:3:12: warning - variable 'x' may be uninitialized here