[racket-dev] racket/match is broken
I've tracked the problem down to reorder-columns.
There are no test cases anywhere for reorder-columns and the code has
no comments on its purpose, so I'm not sure how to fix it.
It seems that the presence of Null and Dummy in the parse of the
pattern causes the app to be lifted out, but I can't tell what to do
to fix it.
I've committed a patch that adds the new tests and comments out the
call to reorder-columns. All existing tests continue to pass, so this
should only lower performance. I'll have to punt fixing it properly to
you Sam.
Jay
On Wed, Oct 5, 2011 at 3:13 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> I found an interesting error in racket/match in my 330 class this afternoon.
>
> (test-case "app pattern"
> (check = 4 (match 3 [(app add1 y) y])))
> (test-case "app pattern (step 1)"
> (check = 2 (match (list 1 3)
> [(list 0 (app add1 y)) y]
> [(list 1 (app sub1 y)) y])))
> (test-case "app pattern (step 2aa)"
> (check = 2 (match (cons 1 3)
> [(cons 0 (app error y)) y]
> [(cons 1 (app sub1 y)) y])))
> (test-case "app pattern (step 2ab)"
> (check = 2 (match (vector 1 3)
> [(vector 0 (app error y)) y]
> [(vector 1 (app sub1 y)) y])))
> (test-case "app pattern (step 2)"
> (check = 2 (match (list 1 3)
> [(list 0 (app error y)) y]
> [(list 1 (app sub1 y)) y])))
>
> If you run these you'll see that the final one ends in an error.
> Basically, it calls the app function on the second element of the list
> even though the head of the list has failed to pattern match. This is
> very dangerous, in my opinion because it means code like...
>
> (match (list password target)
> [(list (== right-password) (app launch-the-missiles success?))
> success?]
> [_
> "Sorry, no nukes for you")
>
> will destroy Canada even though it should not.
>
> 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
>
--
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