[racket] define-match-expander
The match pattern (? number? n) matches number and
binds it to n.
> (match 1 [(? number? n) n])
1
I'd like to write (match 1 [n:num n]) instead.
Since there is no define-identifier-match-expander I have
tried to make (match 1 [(n:num) n]) work. I need a hint.
Here is a non-working attempt:
(define-match-expander n:num
(λ(stx)
(syntax-case stx ()
[(id)
(with-syntax ([n (syntax/loc #'id n)])
#'(? number? n))])))
(check-equal? (match 1 [(n:num) n]) 1)
(check-equal? (match 'x [(n:num) n] [_ 2]) 2)
/Jens Axel
--
Jens Axel Søgaard