Several things here:
- You link to the documentation for CHICKEN 3, which is very very old (back then
match
was part of the core system). You're using CHICKEN 4, which I can see from the fact that you do (use matchable)
at the top, so the docs may not match (pun intended) the matchable version that you're using.
- Please consider updating to CHICKEN 5, as CHICKEN 4 is not actively developed.
- Match is a macro which needs to be able to analyse the pattern at compile-time, which means you cannot pass in a dynamic list (which would happen at run-time). It expands into expressions using
car
, cdr
and so on, based on the pattern which pick apart the input. It can't do that if the pattern is not known at compile-time.
If you really must pass in the pattern dynamically, you could do something like this:
(use matchable)
;; Define patt to be available at the macro expansion level
(define-for-syntax patt '('and (X Y) Z))
;; Make a macro that *expands* to the desired match form
(define-syntax match-patt
(ir-macro-transformer
(lambda (e i c)
`(match ,(cadr e)
(,(i patt) (list ,(i 'X) ,(i 'Y) ,(i 'Z)))))))
;; Actually call the macro to generate the expression
(define prop '(and (#t #t) #t))
(match-patt prop)
Of course this still can only work if the pattern is known at compile-time, so this doesn't really buy you anything unless you're doing really fancy things like reading the pattern at compile-time from a file or something.
When programming in a Lisp (or Scheme), you must always keep in mind at which level of the expansion process you are programming. Usually there are two levels: compile-time and run-time. Macros expand into code at compile-time, so you can never get a macro to operate on information that's available at run-time.
Of course, you could also generate the match expression using eval
. Evaluated code again runs in two phases: macro-expansion occurs first, and running the code happens after that. But because you do this all from within a running program, you can inject expressions that were determined at run-time into eval.