[racket-dev] racket/match is broken

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu Oct 6 18:23:47 EDT 2011

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?

Jay

-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93



Posted on the dev mailing list.