[racket-dev] racket/match is broken
On Thu, Oct 6, 2011 at 6:23 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> On Thu, Oct 6, 2011 at 4:17 PM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
>> On Thu, Oct 6, 2011 at 6:10 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>> In Eli's example, only the second pattern could match
>>>
>>> But if we wrote it this way:
>>>
>>> (define (list?? x) (printf "list-checking ~s\n" x) (list? x))
>>> (define (one?? x) (printf "one-checking ~s\n" x) (eq? 1 x))
>>> (match '(1 (2) 3)
>>> [(list (? one??) (list 2) 3) 1]
>>> [(list _ (? list??) _) 2]
>>> [(list (? one??) (list 20) 30) 3])
>>>
>>> Are you saying that match is allowed to return 1 or 2 depending on
>>> these reorderings and this is in some sense an "illegal" match
>>> expression?
>>
>> No, definitely not!
>>
>> `match' might test components in whatever order it wants, but the
>> semantics of when a match is found is just top-to-bottom, and `match'
>> always takes the first successful match.
>
> So in this case, match has to call one?? because all the other
> components match on the first case?
Exactly.
--
sam th
samth at ccs.neu.edu