[racket] Testing macro helpers

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Sun Apr 7 11:36:24 EDT 2013

I have already done that in the example, the issue is testing the
syntax it produces when called at phase 0.

On Sun, Apr 7, 2013 at 5:04 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> You can put your helper code in a submodule that you require from the test
> module at phase 0 but from the actual module at phase 1.
>
> Robby
>
>
> On Sun, Apr 7, 2013 at 1:47 AM, Eric Dobson <eric.n.dobson at gmail.com> wrote:
>>
>> The issue with that is that it runs the code (compute) at phase1, when
>> I need to run that code at phase 0, otherwise compiling the module
>> runs the tests. I'm willing to muck with eval and namespaces, so I
>> believe what I want should be possible if difficult.
>>
>>
>> On Sat, Apr 6, 2013 at 11:34 PM, Ryan Culpepper <ryanc at ccs.neu.edu> wrote:
>> > 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
>> >
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>
>

Posted on the users mailing list.