[racket] unstable/match
Just now, Brian Mastenbrook wrote:
> On 10/11/2011 02:19 PM, Eli Barzilay wrote:
> > 10 minutes ago, Sam Tobin-Hochstadt wrote:
> >> I don't plan to change it, but I do plan to move it to `racket/match'.
> >
> > Instead of a new keyword, why not use `equal?'? You can then define
> > the others instead of the extra `comparator'. Alternatively, I think
> > that `==' is a bad name, which looks confusing in useful cases like
> >
> > (== 3 =)
> > (== 10<)
> >
> > and I think that the order of compared arguments should change, so
> > the last one matches things that are smaller than 10, and things like
> > `memq' can be used too. Something like
> >
> > (?? 3 =)
> > (?? 10<)
> > (?? memq '(1 2 3))
> >
>
> (?? x) looks a bit funny, doesn't it? Would you get rid of the
> implicit comparator?
Yes, I imagined it requiring the comparator.
> And I think you meant (?? '(1 2 3) memq) in the third example, or
> for the others to be reversed to be more similar to the ? pattern.
Right, should have been:
(?? equal? 4) ; what `==' currently does
(?? = 3)
(?? < 10)
(?? memq '(1 2 3))
Alternatively, and I know that this is stretching it, but `?' is taken
as a keyword anyway, detecting when `?' is used in a form and turning
it into a match predicate, so the above become:
(equal? ? 4)
(= ? 3)
(< ? 10)
(memq ? '(1 2 3))
And this obviously gives you even more -- either direction is easy to
specify, and you get arbitrary arguments, not just two.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!