On Thu, Oct 6, 2011 at 4:17 PM, Sam Tobin-Hochstadt <sa...@ccs.neu.edu> wrote: > On Thu, Oct 6, 2011 at 6:10 PM, Jay McCarthy <jay.mccar...@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 <j...@cs.byu.edu> Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay "The glory of God is Intelligence" - D&C 93 _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/dev