akeep / nanopass-framework-racket

Racket port of the nanopass-framework
MIT License
34 stars 9 forks source link

Unit #1

Closed LeifAndersen closed 9 years ago

LeifAndersen commented 9 years ago

Port Unit tests to racket.

LeifAndersen commented 9 years ago

Eck, I just realized that I clobbered the indentation of some of the languages. I'll fix that...

LeifAndersen commented 9 years ago

Okay, I think that takes care if it.

akeep commented 9 years ago

Cool. These are now integrated. BTW, what is the right way to run the racket tests? (I noticed when test-all.rkt had #lang racket doing racket -r test-all.rkt seemed to import the module, but not execute the contents.

LeifAndersen commented 9 years ago

Usually it's done with raco test file.rkt, although for now you can just run the file with:

racket test-all.rkt

LeifAndersen commented 9 years ago

Hmm...never mind, it looks like racket-mode in emacs is doing something weird that let's it work just fine. When I try to run the racket module it just complains about let-syntax being unbound.

akeep commented 9 years ago

That is odd, I didn’t have a problem with that. I just ended up stripping the #lang racket off the top, then I can do:

racket -r test-all.rkt

I’ll have to give raco test a whirl and see if I can get that working.

-andy:)

On Jan 29, 2015, at 4:08 PM, Leif Andersen notifications@github.com wrote:

Usually it's done with raco test file.rkt, although for now you can just run the file with:

racket all-tests.rkt

— Reply to this email directly or view it on GitHub.

LeifAndersen commented 9 years ago

Yeah the -r flag has it run as a script, which apparently can be run at the top level.

The #lang racket line is just a nice way of typing:

(module some-name racket
   ...)

And now I think I know where the error is coming from, in test-driver.rkt you have the lines:

    (eval `(let-syntax ([if (syntax-rules ()
                              [(_ a b) (if a b (void))]
                              [(_ a b c) (if a b c)])]
                        [cons (syntax-rules () [(_ a b) (mcons a b)])]
                        [set-car! (syntax-rules () [(_ p v) (set-mcar! p v)])]
                        [set-cdr! (syntax-rules () [(_ p v) (set-mcdr! p v)])]
                        [car (syntax-rules () [(_ p) (mcar p)])]
                        [cdr (syntax-rules () [(_ p) (mcdr p)])])
             ,x))))

For some reason, eval in racket works differently from scheme when it's in the module context.

I'll fix that and make a PR.

soegaard commented 9 years ago

FWIW: To get eval to use the namespace from within the module, one must use a namespace-anchor.

(define-namespace-anchor anchor-inside-module)
(define ns  (namespace-anchor->namespace anchor-inside-module))
(define x '(if 1 2))
(eval `(let-syntax ([if (syntax-rules ()
                              [(_ a b) (if a b (void))]
                              [(_ a b c) (if a b c)])]
                        [cons (syntax-rules () [(_ a b) (mcons a b)])]
                        [set-car! (syntax-rules () [(_ p v) (set-mcar! p v)])]
                        [set-cdr! (syntax-rules () [(_ p v) (set-mcdr! p v)])]
                        [car (syntax-rules () [(_ p) (mcar p)])]
                        [cdr (syntax-rules () [(_ p) (mcdr p)])])
         ,x)
      ns)
akeep commented 9 years ago

On January 29, 2015 at 5:33:13 PM, Jens Axel Søgaard (notifications@github.com) wrote: FWIW: To get eval to use the namespace from within the module, one must use a namespace-anchor.

(define-namespace-anchor anchor-inside-module) (define ns (namespace-anchor->namespace anchor-inside-module)) (define x '(if 1 2)) (eval `(let-syntax ([if (syntax-rules () [( a b) (if a b (void))] [( a b c) (if a b c)])] [cons (syntax-rules () [( a b) (mcons a b)])] [set-car! (syntax-rules () [( p v) (set-mcar! p v)])] [set-cdr! (syntax-rules () [( p v) (set-mcdr! p v)])] [car (syntax-rules () [( p) (mcar p)])] [cdr (syntax-rules () [(_ p) (mcdr p)])]) ,x) ns)

Right.  What I’m curious about is (eval `(let-syntax ([ …]) ,x)) was already working for me in Racket 6.1 without specifying the namespace, so I was surprised it was failing for Leif.  Specifying the namespace is fine, and it doesn’t need to pickup the module namespace for our use case (though it is good to know that this is possible)!

Thanks, -andy:)

— Reply to this email directly or view it on GitHub.

LeifAndersen commented 9 years ago

I explained (or at least tried to explain) why I think it works for you but didn't for me on the other PR: https://github.com/akeep/nanopass-framework-racket/pull/2#issuecomment-72117286

FWIW: To get eval to use the namespace from within the module, one must use a namespace-anchor.

Oh, interesting, I didn't know that. Thanks.