[racket-dev] else clauses: possible change to match?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri May 3 17:21:58 EDT 2013

On Friday, May 3, 2013, Neil Toronto wrote:

> On 05/03/2013 09:12 AM, Eli Barzilay wrote:
>
>> A few minutes ago, Robby Findler wrote:
>>
>>> Given that we don't yet even have a prototype of racket2, I'm going
>>> to guess that "near" isn't all that near. IMO, there are other big
>>> things that we should be focused on going first (notably the package
>>> system).
>>>
>>
>> +1, since the "damage" would be that people will need to convert uses
>> `match', but that'll be minor compared to `cond'.
>>
>
> +1, same reasons.
>
> When I don't use match for a while, the first time I use it, I almost
> always write [else ...] as the last clause. Then I catch myself and replace
> `else' with `_'.
>
> I started being careful about catch-all cases in `match' when I wrote an
> expression similar to this:
>
>   (match a
>     [(list x)  #t]
>     [else  (case (first a)
>              [(6)  #f]
>              [else  #t])])
>
> got this error:
>
>   case: bad syntax (not a datum sequence) in: else
>
> and was completely baffled for a long time.
>
>  A few minutes ago, J. Ian Johnson wrote:
>>
>>> I've used else as a catch-all binding in match. Yes, it's not the
>>> best practice, but I think since I've done it, other people must
>>> have done it too. This could annoy them.
>>>
>>
>> Do you have an actual use that would *break*?  That is, something like
>>
>>      (match x ... [else else])
>>
>
> I'll bet almost every use of just `else' as a pattern in the wild doesn't
> have `else' in the body because it's intended to be a catch-all case. If it
> does have `else' in the body, it's almost certainly in a `cond' or a
> `case', which is either an error or hideous style.
>
>
FWIW, this was the bug in redex that prompted me to send this message (it
was there for some time since it wasn't a syntax error .... it was similar
in spirit to the code I posted; things broke when #f was an argument)

Robby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130503/30167659/attachment.html>

Posted on the dev mailing list.