[racket] Testing macro helpers

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Sun Apr 7 02:34:11 EDT 2013

On 04/07/2013 01:24 AM, Eric Dobson wrote:
> I am trying to test a helper to a macro. It generates a syntax object
> with bindings at phase-1, this is then returned by the macro and it
> correctly evaluates. Is there a way to not go through the macro, but
> still evaluate the syntax-object with those bindings it has at phase-1
> relative to the helper and not phase 0 relative?
>
> Example code:
> #lang racket/load
>
> (module t racket
>    (provide (all-defined-out))
>    (define temp 7))
>
> (module stx-compute racket
>    (provide (all-defined-out))
>    (require (for-template 't))
>    ;(require 't)
>    (define (compute) #'temp))
>
>
> (module stx racket
>    (provide (all-defined-out))
>    (require (for-syntax 'stx-compute))
>    (define-syntax (use-compute stx)
>      (compute)))
>
> (require 'stx)
> (displayln (use-compute))
> (require 'stx-compute)
> (displayln (eval-syntax (compute)))
>
> This fails on the eval-syntax, but succeds if I uncomment the (require 't).

You might find phase1-eval from unstable/macro-testing helpful.

(require (for-syntax 'stx-compute)
          unstable/macro-testing))

(phase1-eval (compute))
;; => 'temp

(phase1-eval (compute) #:quote quote-syntax)
;; => #<syntax temp>

(eval-syntax (phase1-eval (compute) #:quote quote-syntax))
;; => 7

Ryan


Posted on the users mailing list.