Possible ambiguity in pattern-matching and renaming semantics Daphne Preston-Kendal (28 Jul 2021 19:22 UTC)
Re: Possible ambiguity in pattern-matching and renaming semantics Marc Nieper-Wißkirchen (28 Jul 2021 21:11 UTC)
Re: Possible ambiguity in pattern-matching and renaming semantics Marc Nieper-Wißkirchen (29 Jul 2021 06:14 UTC)
Re: Possible ambiguity in pattern-matching and renaming semantics Marc Nieper-Wißkirchen (13 Aug 2021 12:17 UTC)
Re: Possible ambiguity in pattern-matching and renaming semantics Daphne Preston-Kendal (14 Oct 2021 12:33 UTC)

Possible ambiguity in pattern-matching and renaming semantics Daphne Preston-Kendal 28 Jul 2021 19:22 UTC

Alexis King posed the following brain teaser on Scheme and asserted that it’s a case where the semantics of pattern-matching and identifier renaming are poorly-defined.

> If you know Scheme: without checking, what do you think the following expressions evaluate to?
>
> (let ([x 'outer])
>   (define-syntax-rule (m a)
>     (let ([a 'inner]) x))
>   (m x))
>
> (let ([x 'outer])
>   (define-syntax-rule (m a)
>     (begin
>       (define a 'inner)
>       x))
>   (m x))
<https://twitter.com/lexi_lambda/status/1420221128245714951>

I don’t want to start an informal debate about ‘intuitive’ reasons for one or the other answer here (Twitter is the place to do that, and the diversity of replies suggest that such a discussion could be never-ending), but rather ask if this really is a poorly-defined case in syntax-rules/syntax-case pattern replacement according to R5/R6/R7RS, and if so whether SRFI 211 might be able to tighten this up, at least in the case of syntax-case.

For the record, Racket, Chez, Guile, Gerbil, Chibi, Sagittarius, and MIT Scheme (altogether, at least five independent implementations of syntax-rules, I think) agree that the results are 'outer, 'inner. Chicken thinks it’s 'outer, 'outer, as do an absolute majority of respondents to Alexis’s poll as at time of writing. I don’t have other implementations at hand to test on.

Daphne