[racket] strange behaviour of a (match) form
In this context, null is just a variable and it gets bound to what it matches:
> Welcome to Racket v6.1.0.8.
> > (match 'hello-world [null null])
> 'hello-world
On Oct 1, 2014, at 4:52 PM, Yuri Garmay <yuri.from.spb at gmail.com> wrote:
> Hi, all
>
> Accidentally, I found out that null matchs in unexpected way (seems it matchs always)
>
> So,
> (define (length-my list)
> (match list
> ['() 0]
> [(cons x xs)
> (+ 1
> (length-my xs))]
> [_ 'not-a-list]))
> (length-my '(1 2 3 4))
> >produces 4
>
> But
> (define (length-my list)
> (match list
> [null 0]
> [(cons x xs)
> (+ 1
> (length-my xs))]
> [_ 'not-a-list]))
> (length-my '(1 2 3 4))
> >produces 0
>
> I also tried that:
> (match '213423
> [null 0]
> [_ 1])
> >produces 0
> (match null
> ['213423 0]
> [_ 1])
> >produces 1
>
> Is it a bug?
>
> I am using Racket 6.1
>
> --
> Best regards,
> Yuri
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users