[racket] define-match-expander and the second proc-expr for when it's not a match pattern

From: Alexander D. Knauth (alexander at knauth.org)
Date: Sun Jul 20 13:10:01 EDT 2014

Is there a way to supply a rename transformer instead of a procedure for it to use when it’s not used as a match pattern?

If I do something like this:

#lang racket

(require (for-syntax syntax/parse))

(define-match-expander my-list
  (lambda (stx) ; to use when it’s a match pattern, works
    (syntax-parse stx
      [(my-list stuff:expr ...)
       #'(list stuff ...)]))
  (make-rename-transformer #'list)) ; to use when it’s not a match pattern, doesn’t work

(match '(1 2 3)
  [(my-list one two three) ; works
   (list one two three)])

(my-list 1 2 3) ; doesn’t work

It gives me this error:
. . ../../Applications/Racket v6.0.1.8/collects/syntax/wrap-modbeg.rkt:46:4: application: not a procedure;
 expected a procedure that can be applied to arguments
  given: #<rename-transformer>
  arguments...:
   #<syntax:16:0 (my-list 1 2 3)>

Is there a way to supply a rename transformer instead of a procedure for it to use when it’s not used as a match pattern?



Posted on the users mailing list.