<div dir="ltr">Oh, right! Thanks! I'll push something that explicitly mentions underscore and adjust the elses to use underscores.<div style><br></div><div style>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sat, May 4, 2013 at 9:09 PM, Greg Hendershott <span dir="ltr"><<a href="mailto:greghendershott@gmail.com" target="_blank">greghendershott@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There will be people who see the long BNF for match in the Reference,<br>
and flee to the Guide to try to learn by example instead. Even when<br>
they later do read the Reference carefully, they'll be left with first<br>
impressions of idioms from the Guide.<br>
<br>
(I might be one of those people. Cough.)<br>
<br>
The Guide <<a href="http://docs.racket-lang.org/guide/match.html" target="_blank">http://docs.racket-lang.org/guide/match.html</a>> uses `else`<br>
in a couple examples.<br>
<br>
Also, I somehow got the idea that `(var x)` was the only way to do<br>
what `else` can do by accident. So I don't _think_ I have any code<br>
that's buggy this way, or, which would break if the change were made,<br>
either way. I think.<br>
<br>
Until I saw your email I didn't appreciate why it would make sense to<br>
use `_`. Going forward I will.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Fri, May 3, 2013 at 9:39 AM, Robby Findler<br>
<<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>> wrote:<br>
> [ for those that just want to see what I'm getting at, scroll to the end ]<br>
><br>
> While the docs are clear (enough) on this point, I think it can be quite<br>
> confusing. See if you spot the bug in this program:<br>
><br>
> #lang racket<br>
> (define (find-literals e)<br>
> (define literals '())<br>
> (let loop ([e e])<br>
> (match e<br>
> [`(λ (,x) ,e)<br>
> (loop e)]<br>
> [`(,e1 ,e2)<br>
> (loop e1)<br>
> (loop e2)]<br>
> [(? symbol?) (void)]<br>
> [else<br>
> (cond<br>
> [(member e literals)<br>
> (void)]<br>
> [else<br>
> (set! literals (cons e literals))])]))<br>
> literals)<br>
><br>
> (module+ test<br>
> (require rackunit)<br>
> (check-equal? (find-literals '(λ (x) x)) '())<br>
> (check-equal? (find-literals '((λ (x) x) 1)) '(1))<br>
> (check-equal? (find-literals '((λ (x) x) #f)) '(#f)))<br>
><br>
><br>
> Hint: the last test case fails. Second hint: if you switch it to use sets,<br>
> it starts working. Third hint: this isn't about lists. :)<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> The bug is that 'else' is treated as a variable in match, so it gets bound<br>
> to #f, which shadows the else in the cond which .... is confusing.<br>
><br>
> So, how about making match treat else specially?<br>
><br>
><br>
> I don't ask this completely from outer space; there was a bug in Redex's<br>
> random generation that was caused exactly by this shadowing of else.<br>
><br>
> Robby<br>
><br>
><br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _________________________<br>
> Racket Developers list:<br>
> <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
><br>
</div></div></blockquote></div><br></div>