You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a limitation, apparently, of the Racket version. Racket's (case ...) quotes its matching clauses, so they are not actually evaluated, just compared to the value expression with equal?
(select case 1
((mod 5 2) 'foo)
((mod 2 2) 'bar))
; expect 'foo, but falls through instead.void
I think the case can be made for writing our own (select case ...) to allow for this usage. It's a common enough behavior in other language's case statements, so if it's possible to do with Racket's macros I think it's worth implementing.
The text was updated successfully, but these errors were encountered:
Racket apparently does provide an alternate case in the old mzscheme libraries that works more like our previous second example. With evcase you can do this for example:
(require mzlib/etc)
(for ([n (in-range 1 101)])
(evcase 0
((+ (modulo n 5)
(modulo n 3)) (displayln "FizzBuzz"))
((modulo n 5) (displayln "Buzz"))
((modulo n 3) (displayln "Fizz"))
(else (displayln n))))
I've mocked up a simple case macro that supports the best of both features, but the discussion in the mailing list seems to indicate there may be performance costs to allowing both a list of matching values and matching expressions in the same block. I don't consider performance as high on the list of priorities as ease of use and syntax power though, so this may not necessarily be worth worrying about yet.
This is a limitation, apparently, of the Racket version. Racket's (case ...) quotes its matching clauses, so they are not actually evaluated, just compared to the value expression with equal?
So this works:
But this doesn't:
I think the case can be made for writing our own (select case ...) to allow for this usage. It's a common enough behavior in other language's case statements, so if it's possible to do with Racket's macros I think it's worth implementing.
The text was updated successfully, but these errors were encountered: