Summary

Reserved pattern symbols break when a binding of the same name exists

Metadata

Description

When reserved pattern symbols like ? or _ are bound in the lexical environment of a match expression, they don't work anymore:

 (import matchable)
 
 (let ((? 1))
   (match '(x y)
     ((? odd?) (print ?))))
 
 (match '(x y)
   ((_ _) (print 'ok)))
 
 (let ((_ 1))
   (match '(x y)
     ((_ _) (print 'ok))))

Output:

 $ csc matchbug.scm && ./matchbug
 x
 ok
 
 Error: (match) no matching pattern
 
 	Call history:
 
 	matchbug.scm:5: print	  
 	matchbug.scm:8: print	  
 	matchbug.scm:10: failure391	  
 	matchbug.scm:10: error	  	<--

Changes and comments

[2014-09-04 14:21:48 UTC] syn wrote:

Just for the record: The same happens with Chibi 0.7.

[2014-09-04 14:32:00 UTC] ashinn changed status from new to closed

[2014-09-04 14:32:00 UTC] ashinn set resolution to wontfix

[2014-09-04 14:32:00 UTC] ashinn wrote:

This is basically just hygiene working as expected, and gives that result for the same reason that

 (let ((else #f))
   (cond (else #t) (#t #f)))

returns #f.

Admittedly this is one of those cases where it's not useful to match the operator position id against the current lexical scope and one might be tempted to deliberately match unhygienically. However, this may change in future versions. Moreover, other macros which expand into match may depend on the fact that inserted identifiers match hygienically.

[2014-09-04 14:59:05 UTC] syn wrote:

Indeed, we just discussed this issue on IRC and came to the same conclusion. I guess it's just a fact of life^WScheme we have to live with, then. Perhaps it would be worthwhile to add a caveat section about this to the manual?

Anyhow, thanks for the quick response!