(module views mzscheme
(require (lib "plt-match.ss"))
(define-match-expander view
(lambda (stx)
(syntax-case stx ()
[(_ pred? ((selector pattern) ...))
#'(? pred? (app selector pattern) ...)])))
(define-syntax define-view
(lambda (stx)
(syntax-case stx ()
[(_ view-name pred? (selector ...))
(with-syntax ([(pattern-var ...)
(generate-temporaries #'(selector ...))]
[(pred-var) (generate-temporaries #'(pred?))]
[(selector-var ...)
(generate-temporaries #'(selector ...))])
#'(begin
(define pred-var pred?)
(define selector-var selector) ...
(define-match-expander view-name
(lambda (stx)
(syntax-case stx ()
[(_ pattern-var ...)
#'(? pred? (app selector pattern-var) ...)])))))])))
(provide view define-view))