How are vector patterns used in syntax rules?

I write Common Lisp macros, so Scheme R5Rs macros are a bit unnatural for me. I think I got an idea, except that I donโ€™t understand how to use vector patterns in syntax rules:

(define-syntax mac (syntax-rules () ((mac #(abcd)) (let () (display a) (newline) (display d) (newline))))) (expand '(mac #(1 2 3 4))) ;; Chicken expand-full extension shows macroexpansion => (let746 () (display747 1) (newline748) (display747 4) (newline748)) 

I don't see how to use a macro that requires its arguments to be written as a vector:

 (mac #(1 2 3 4)) => 1 4 

Is there any method that uses these patterns?

Thanks!

+6
macros lisp scheme
source share
1 answer

A macro may not require its arguments to be written as a vector, but they provide useful behavior. The most notable example is a quasiquadrat:

 ;; a couple of test variables (define foo 1) (define bar 2) ;; vector literals in Scheme are implicitly quoted #(foo bar) ; returns #(foo bar), ie a vector of two symbols ;; however quasiquote / unquote can reach inside them `#(,foo ,bar) ; returns #(1 2) 

For another example, see this pattern matching package , which allows vector matching and thus uses vector patterns in its macro definitions (included in the packageโ€™s metadata associated with the page).

+1
source share

All Articles