We do have warnings for things like the optimizer detecting a bad application of a function, for example, but they go into the logger and you have to say the magic words (open sesame?) to get them out.<div><br></div><div>For this kind of thing, my preference would be to change match than to issue a warning. I don't like warnings that are basically admitting weaknesses in the language design.... Of course, changing a core thing like that may be more trouble than it is worth, due to backwards compatibility concerns, which is why I think it is worth raising here to see what others think.</div>
<div><br></div><div>Alternatively, we could revisit 'else' in racket2 and leave racket alone.</div><div><br></div><div>Robby<br><br>On Friday, May 3, 2013, Laurent wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>That one is twisted indeed, if you forget about how `else' must be written in `match' (which I had, not using match too much).<br>I was thinking about issuing a warning when a syntax-parameter gets shadowed (if that is even catchable).<br>
Then suddenly I realized Racket doesn't do warnings. (Is there a reason for that?)<br><br></div>Laurent<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 3, 2013 at 3:39 PM, Robby Findler <span dir="ltr"><<a href="javascript:_e({}, 'cvml', 'robby@eecs.northwestern.edu');" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>[ for those that just want to see what I'm getting at, scroll to the end ]</div><div><br></div>While the docs are clear (enough) on this point, I think it can be quite confusing. See if you spot the bug in this program:<div>
<br></div><div><div>#lang racket</div><div>(define (find-literals e)</div><div> (define literals '())</div><div> (let loop ([e e])</div><div> (match e</div><div> [`(λ (,x) ,e)</div><div> (loop e)]</div>
<div> [`(,e1 ,e2)</div><div> (loop e1)</div><div> (loop e2)]</div><div> [(? symbol?) (void)]</div><div> [else</div><div> (cond</div><div> [(member e literals)</div><div> (void)]</div>
<div> [else </div><div> (set! literals (cons e literals))])]))</div><div> literals)</div><div><br></div><div>(module+ test </div><div> (require rackunit)</div><div> (check-equal? (find-literals '(λ (x) x)) '())</div>
<div> (check-equal? (find-literals '((λ (x) x) 1)) '(1))</div><div> (check-equal? (find-literals '((λ (x) x) #f)) '(#f)))</div></div><div><br></div><div><br></div><div>Hint: the last test case fails. Second hint: if you switch it to use sets, it starts working. Third hint: this isn't about lists. :)</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>
<div><br></div><div><br></div><div><br></div><div>The bug is that 'else' is treated as a variable in match, so it gets bound to #f, which shadows the else in the cond which .... is confusing.</div><div><br></div>
<div>
So, how about making match treat else specially?</div><div><br></div><div><br></div><div>I don't ask this completely from outer space; there was a bug in Redex's random generation that was caused exactly by this shadowing of else.</div>
<span><font color="#888888">
<div><br></div><div>Robby</div><div><br></div><div><br></div><div><br></div>
</font></span><br>_________________________<br>
Racket Developers list:<br>
<a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div>