Am Mi., 6. März 2024 um 20:11 Uhr schrieb Sergei Egorov <e...@acm.org>:

>
> I don’t think that this is formally correct. SRFI 251 derives its
> semantics from R7RS, and no longer relaxes R7RS requirement for body-level
> ‘begins’ to be either ‘definition begins’ (i.e. contain only definitions)
> or ‘expression begins’ (i.e. contain only expressions).
>

This would be incompatible with R6RS, in which body-level begin has
splicing semantics and can contain any kind of form. The same seems to be
true for R7RS's first form of begin (4.2.3.). Or have I misunderstood you?


> I believe this puts your second definition of ‘define-number’ into
> undefined territory: if expanded on body level, it yields a ‘begin’ with
> 'it is an error' behavior, as in R7RS. To make the second ‘define-number’
> work as intended, it should be changed to something like this:
>
> (define-syntax define-number
>   (syntax-rules ()
>     ((_ id val)
>      (begin
>        (define tmp val)
>        (define-values () (begin (unless (number? tmp) (error "boom!"))
> (values)))
>        (define id tmp)))))
>
> As we have discussed earlier at some point, perhaps it makes sense to
> supplement this SRFI with a derived form that makes such code easier to
> read, e.g.
>
>        (define! (unless (number? tmp) (error "boom!")))
>
>
> On Wednesday, March 6, 2024 10:18:19 AM (-05:00), Marc Nieper-Wißkirchen
> wrote:
>
> A problem with SRFI 251's approach is that macros can gain unwanted spooky
> actions at a distance.
>
> Consider the following expression E:
>
> (let ((x 1))
>   (define (f) x)
>   (define-number y 42)
>   (define x 2)
>   (f))
>
> Here, define-number is defined through
>
> (define-syntax define-number
>   (syntax-rules ()
>     ((_ id val) (define id val))))
>
> Evaluating E gives 2.
>
> Now the author of define-number decides to change its definition to
>
> (define-syntax define-number
>   (syntax-rules ()
>     ((_ id val)
>      (begin
>        (define tmp val)
>        (unless (number? tmp) (error "boom!"))
>        (define id tmp)))))
>
> This is possible with SRFI 251. However, suddenly evaluating E gives 1.
>
> R6RS and R7RS solve this problem by making E together with the second
> version of define-number an error.
>
> SRFI 245 doesn't have this problem.
>
> Am Mi., 6. März 2024 um 02:55 Uhr schrieb Arthur A. Gleckler <
> s...@speechcode.com>:
>
>> I've just published draft #3 of SRFI 251
>> <https://srfi.schemers.org/srfi-251/>. It was submitted by Sergei
>> Egorov, author of the SRFI.
>>
>> Here are Sergei's comments on the draft:
>>
>> Here is a third draft with an extra example (and test), demonstrating the
>> 'staged' nature of define-syntax in stfi-251: macros defined in a
>> definition group can be used in downstream expressions and definition
>> groups.
>>
>> Here is the commit summary:
>>
>>    - "Staged" define-syntax example added
>>    - Drop trailing whitespace.
>>    - Publish third draft.
>>
>> Here's the diff:
>>
>>
>> https://github.com/scheme-requests-for-implementation/srfi-251/compare/draft-2..draft-3
>>
>> Regards,
>>
>> SRFI Editor
>>
>
>

Reply via email to