[plt-scheme] Problem with plt-match.ss `and' pattern

From: David Van Horn (dvanhorn at cs.uvm.edu)
Date: Tue Jan 18 16:40:32 EST 2005

I've noticed the following problem with the way plt-match.ss compiles the 
`and' pattern.  Consider:

(match 'x
   ((and (not (? symbol?)) (? odd?)) #t)
   (_ #f))


(let ((x 'x))
   (if (odd? x)
       (if (symbol? x)
           ((lambda () #f))
           ((lambda () #t)))
       ((lambda () #f))))

I would expect the above match expression to evaluate to #f, but instead 
results in a type error because odd? is applied to a symbol, as can be seen in 
the compiled code.

Note that the following compiles correctly:

(match 'x
   ((and (? number?) (? odd?)) #t)
   (_ #f))


(let ((x 'x))
   (if (and (number? x) (odd? x))
       ((lambda () #t))
       ((lambda () #f))))

Although I have seen the same problem also arises in expressions such as:

(match '(1 2 3 a)
   ((and (list (? number?) ...)
         (? (lambda (ls) (apply + ls))))


Posted on the users mailing list.