[racket-dev] else clauses: possible change to match?
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.
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.
Alternatively, we could revisit 'else' in racket2 and leave racket alone.
Robby
On Friday, May 3, 2013, Laurent wrote:
> That one is twisted indeed, if you forget about how `else' must be written
> in `match' (which I had, not using match too much).
> I was thinking about issuing a warning when a syntax-parameter gets
> shadowed (if that is even catchable).
> Then suddenly I realized Racket doesn't do warnings. (Is there a reason
> for that?)
>
> Laurent
>
>
> On Fri, May 3, 2013 at 3:39 PM, Robby Findler <robby at eecs.northwestern.edu<javascript:_e({}, 'cvml', 'robby at eecs.northwestern.edu');>
> > wrote:
>
>> [ for those that just want to see what I'm getting at, scroll to the end ]
>>
>> 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:
>>
>> #lang racket
>> (define (find-literals e)
>> (define literals '())
>> (let loop ([e e])
>> (match e
>> [`(λ (,x) ,e)
>> (loop e)]
>> [`(,e1 ,e2)
>> (loop e1)
>> (loop e2)]
>> [(? symbol?) (void)]
>> [else
>> (cond
>> [(member e literals)
>> (void)]
>> [else
>> (set! literals (cons e literals))])]))
>> literals)
>>
>> (module+ test
>> (require rackunit)
>> (check-equal? (find-literals '(λ (x) x)) '())
>> (check-equal? (find-literals '((λ (x) x) 1)) '(1))
>> (check-equal? (find-literals '((λ (x) x) #f)) '(#f)))
>>
>>
>> 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. :)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 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.
>>
>> So, how about making match treat else specially?
>>
>>
>> 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.
>>
>> Robby
>>
>>
>>
>>
>> _________________________
>> Racket Developers list:
>> http://lists.racket-lang.org/dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130503/9ca6b036/attachment-0001.html>