Email list hosting service & mailing list manager

Re: Lexical scope of pattern variables is not strictly respected in the sample implementation Marc Nieper-Wißkirchen (01 Sep 2020 09:25 UTC)

Re: Lexical scope of pattern variables is not strictly respected in the sample implementation Marc Nieper-Wißkirchen 01 Sep 2020 09:25 UTC

Sorry, typo on my side.

My example (corrected) has meant to be

(match '1 ((and odd? (? odd?)) odd?))

Am Di., 1. Sept. 2020 um 11:21 Uhr schrieb Felix Thibault
<xxxxxx@gmail.com>:
>
>
>
> On Tue, Sep 1, 2020 at 4:35 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>
>> In the specification section of SRFI 204, it says "identifiers will
>> match anything, and make the corresponding binding available in the
>> body", which I read as that the identifiers are lexically bound in an
>> extended environment, in which the body is evaluated.
>>
>> The sample implementation, however, fails to respect the correct
>> lexical scoping in some cases:
>>
>> (match '1 ((and odd (? odd)) odd))
>>
>> The expected value of this expression (and according to how match is
>> specified in SRFI 204) is 1. The sample implementation, however, fails
>> with an error because the binding of odd is introduced too early,
>> namely in a scope surrounding the pattern `(? odd)` as well.
>>
>> To make the sample implementation do the correct thing, it has to
>> defer all actual bindings or bind to temporary variables first.
>>
>> Marc
>
>
> Unless I'm misunderstanding
> (match '1 ((and odd (? odd)) odd))
> needs a predicate like either:
> (match '1 ((and odd (? odd?)) odd))
> or
> (match '1 ((and odd (? odd? odd)) odd))
> both of which evaluate to 1