Expression/Definition dependency semantics Dr. Arne Babenhauserheide (24 Sep 2023 15:44 UTC)
Re: Expression/Definition dependency semantics Daphne Preston-Kendal (24 Sep 2023 15:54 UTC)
Re: Expression/Definition dependency semantics Dr. Arne Babenhauserheide (24 Sep 2023 16:52 UTC)
Re: Expression/Definition dependency semantics Amirouche (24 Sep 2023 20:39 UTC)
Re: Expression/Definition dependency semantics Dr. Arne Babenhauserheide (25 Sep 2023 10:20 UTC)
Re: Expression/Definition dependency semantics Marc Nieper-Wißkirchen (25 Sep 2023 11:33 UTC)
Re: Expression/Definition dependency semantics Daphne Preston-Kendal (24 Sep 2023 21:14 UTC)
Re: Expression/Definition dependency semantics Dr. Arne Babenhauserheide (25 Sep 2023 10:04 UTC)
Re: Expression/Definition dependency semantics Amirouche (24 Sep 2023 20:12 UTC)

Re: Expression/Definition dependency semantics Daphne Preston-Kendal 24 Sep 2023 15:54 UTC

On 24 Sep 2023, at 08:49, Dr. Arne Babenhauserheide <xxxxxx@web.de> wrote:

> Do I understand it correctly that this would mean that this would not
> work, because
>
> (define (using-later-procedure)
>  (define x (y))
>  (define (y) #t)
>  x)
>
> Or that it would stop to work if I interspersed logging messages?
>
> (define (using-later-procedure)
>  (define x (y))
>  (display x)(newline)
>  (define (y) #t)
>  x)
>
> Both of these work in Guile, because Guile treats expressions before the
> final definition as implicit definitions:
>
> (define (using-later-procedure)
>  (define x (y))
>  (define _1 (display x))
>  (define _2 (newline))
>  (define (y) #t)
>  x)
>
> For details, see
> https://www.gnu.org/software/guile/manual/html_node/Internal-Definitions.html

None of these should work. The last one also not in a Scheme before SRFI 245 according to RnRS, and I’m a bit baffled that it does in Guile. The fact the intermediate logging expressions are converted to definitions is of no relevance: y is called in the right-hand side of x’s definition before y is defined. RnRS Scheme does not allow this.

Even more bafflingly, this version of using-later-procedure does not work, but the one you gave does:

(define (using-later-procedure)
   (define x (y))
   (define _1 (display x))
   (define _2 (newline))
   (define y (begin (display "y defined\n") (lambda () #t)))
   x)

I have no idea what Guile is doing that this is possible.

Note that the first example on the Guile manual page you linked does not violate the restriction imposed by this SRFI (or by RnRS specs), because the *value* of apple is not needed until banana is called.

> Do I understand the letrec* implementation in the SRFI correctly that it
> would enforce the ordering of expressions before the directly following
> definition?

Yes.

Daphne