I received this report with a request to forward it to WG1. You who receive this message are WG1 for this purpose. Please discuss.
---------- Forwarded message ---------
From: Marc Feeley <fee...@iro.umontreal.ca>
Date: Tue, Oct 23, 2018 at 5:21 PM
Subject: issue with internal define and define-values
To: John Cowan <co...@ccil.org
Hi John. I’m not sure where to send this issue report on R7RS small. I hope you can forward it to the committee for discussion.
The specification of internal define and define-values in the R7RS is misleading because it says that the variable(s) is/are *bound* to the value(s). But because internal definitions are transformed to a letrec* they are in fact assigned, similarly to top-level defines. This is an important aspect which affects the semantics of closures that close over internally defined variables when continuations are used to “repeat” a definition.
Below is some code that shows the issue for define-values. I tested it with Chicken, Guile and Chez and got two different results. Which one is the semantics intended by the R7RS spec?
(define (p x)
(define (f x)
(k (* x x) k))))
(define closures '())
(define-values (n again)
(set! closures (cons (lambda () n) closures))
(let ((next (- n 1)))
(set! n (+ n 1000))
(if (>= next 0)
(again next again))))
(p ((list-ref closures 0)))
(p ((list-ref closures 1)))
(p ((list-ref closures 2)))
(p ((list-ref closures 3)))
(p ((list-ref closures 4)))
;; Chicken and Guile: