[plt-scheme] Shortening the rope in the matcher

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Feb 18 19:17:51 EST 2005

I just spent an hour hunting down a bug in the Galore red/black tree
implementation. Here was the offending function:

(define (unbalanced-right s)
   (match s
     [($ R t1 x1 ($ B t2 x2 t3))             (values (rbalance t1 x1 (R- t2 x2 t3)) #f)]
     [($ B t1 x1 ($ B t2 x2 t3))             (values (rbalance t1 x1 (R- t2 x2 t3)) #t)]
     [($ B t1 x1 ($R ($ B t2 x2 t3) x3 t4))  (values (B- (rbalance t1 x1 (R- t2 x2 t3)) x3 t4) #f)]
     [_                                      (error)]))


The bug was the missing space between $ and R.

Would the restriction "no pattern variable can start with $"
be a useful restriction in the pattern matcher?

-- 
Jens Axel Søgaard




Posted on the users mailing list.