[racket] empty in patterns

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Sep 29 10:08:39 EDT 2010

On Wed, Sep 29, 2010 at 8:14 AM, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:
> Is it correct that one can write (cons a d) in a pattern, but not empty?  Thus,
>
> (define (insert-many ns s)
>  (match ns
>    [(? empty?) s]
>    [(cons a d) (insert a
>                        (insert-many d s))]))
>
> works but
>
> (define (insert-many ns s)
>  (match ns
>    [empty s]
>    [(cons a d) (insert a
>                        (insert-many d s))]))
>
> does not have the intended semantics.  This seems unfortunate given
> that we've adopted HtDP-style lists, as opposed to traditional Scheme
> lists, into Racket wholesale.

I'm not sure what this last statement means, but all `match' special
forms come after a paren, and so that pattern can't work. Note that
`null', if that's what you mean by "traditional Scheme lists", doesn't
have special meaning in `match either. If you're ok with:

[(empty) s]

then you can write a match expander to do that.

-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.