[plt-dev] define-match-expander <-> unlib.plt doesn't compile

From: Sam TH (samth at ccs.neu.edu)
Date: Fri Nov 13 08:57:48 EST 2009

On Fri, Nov 13, 2009 at 4:19 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> John Clements wrote:
>>
>> Dave Gurnell wrote:
>>>
>>> I've uploaded Unlib 3.19 containing a fix for the match problem.
>>
>> Awesome fixed now thanks all.
>
> Hi all,
>
> I haven't managed to fix this in its entirety and I'm not sure how to go
> about it correctly.
>
> The eq? match expander now looks like this:
>
> ; (_ expr pattern ...)
> (define-match-expander match:eq?
>  (lambda (stx)
>    (syntax-case stx ()
>      [(_ expr pattern ...)
>       #'(? (cut eq? <> expr) pattern ...)]))
>  (lambda (stx)
>    (syntax-case stx ()
>      [_ #'eq?])))
>
> However, the second transformer procedure only works if eq? is in
> application position. Looking at the docs, I assume I want to use
> make-rename-transformer in some way but I can't work out how in this
> context.

Unfortunately, the result of `make-rename-transformer' isn't a
procedure (Matthew, could this be changed?), so you can't use it here.
 This is probably the next best thing:

; (_ expr pattern ...)
(define-match-expander match:eq?
 (lambda (stx) #f)
  (lambda (stx)
    (syntax-case stx (set!)
      [(nm . args) #'(eq? . args)]
      [nm (identifier? #'nm) #'eq?]
      [(set! . _)
       (raise-syntax-error #f "match expander cannot be target of a
set!" stx)])))

(match:eq? 1 1)


-- 
sam th
samth at ccs.neu.edu


Posted on the dev mailing list.