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)

Expression/Definition dependency semantics Dr. Arne Babenhauserheide 24 Sep 2023 06:49 UTC
Hi,

thank you for creating SRFI-245! In Guile I enjoy it very much to be
able to intersperse definitions and expressions.

The specification in SRFI-245 looks a bit too strict for me, though:

> It is an error for the evaluation of any expression or of the
> right-hand side of any definition in the sequence of definition or
> expressions to require knowledge of the value of a variable whose
> definition is to the right of it.

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

>      (let ()
>        (define a 1)
>        (foo)
>        (define b 2)
>        (+ a b))
>
> is equivalent to
>
>      (let ()
>        (letrec* ((a 1) (_ (begin (foo) #f)) (b 2))
>          (+ a b)))

It may be useful to enforce an ordering between expressions and blocks
of definitions, though, to ensure that logging code runs before the
later definitions.

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

Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de