On Sat, Nov 20, 2010 at 04:00:26PM +0100, Felix wrote: > From: Alan Post <[email protected]> > Subject: [Chicken-users] keyword args not assigned in program. > Date: Sat, 20 Nov 2010 06:59:38 -0700 > > > I'm dealing with a frustrating bug--I haven't been able to turn it > > into a simple test case. Will you let me explain what is going on, > > why I haven't been able to make a test case, and then offer advice? > > > > I have a compiler to convert a PEG grammar to scheme. In my test > > suite, I have a line: > > > > <++> tests/run.scm > > (set! compiler (eval (compile "test.peg"))) > > <--> > > > > The test.peg file references a symbol defined in tests/run.scm, and > > I run the compiler with some sample data: > > > > <++> tests/run.scm # this test fails! > > (define (transform #!rest rest #!key key0) > > (pretty-print rest) > > key0) > > > > (set! compiler (eval (compile "test.peg"))) > > > > (compiler "a") > > <--> > > > > The compiler works, it calls |transform|, but the #!key arguments to > > transform are not properly mapped. |rest| is: > > > > (key0: 0 key1: 1) > > > > but |key0| is: > > > > #f > > > > So my #!rest arguments are seeing the tagged values, but the tagged > > values aren't being assigned to #!key arguments. > > > > That is simple enough to diagnose. I've made my |test.peg| file, > > the one I'm compiling, as simple as possible. I want to remove the > > compiler, because it is hands down the largest part of the test. > > > > I run |(compile "teg.peg")| and save the output to |"out.scm"|, > > converting my test to this: > > > > <++> tests/run.scm # this test works! > > (define (transform #!rest rest #!key key0) > > (pretty-print rest) > > key0) > > > > (call-with-output-file "out.scm" > > (lambda (port) > > (write (compile "test.peg") port))) > > (set! compiler (eval (call-with-input-file "out.scm" read))) > > > > (compiler "a") > > <--> > > > > I have a temporary file that I write and then read. The output of > > the compiler is the same, but the method that the sexpr is evaluated > > changes to have an intermediate file. > > > > Suddenly, my test works and |key0| receives the correct value. > > > > It appears that directly evaluating the result of the compiler causes > > #!key arguments not to be assigned, but if I save that same result > > and read it back in, things work fine. > > > > What is going on?! My closest guess is that I have some kind of gc > > problem that I only trigger with a program of a particular size. I'm > > not sure where to go from here, as the test case is still a few > > thousand lines of code, given that the compiler seems integral to > > the test case. > > > > How do the call-sites of `transform' look? Have you tried to > trace `transform' (using the `trace' egg)? That way you can > see how it is invoked. Don't worry about the GC - you would get > much more weird errors than this. >
The trace resulting from the write/read/eval variation looks like this: procedure (f_438 . args84)> (key0: 0 key1: 1)) [0] (transform key0: 0 key1: 1) (key0: 0 key1: 1) [0] transform -> 0 While the trace resulting from the (eval (compile ...)) looks like this: procedure (f_438 . args84)> (key0: 0 key1: 1)) [0] (transform key0: 0 key1: 1) (key0: 0 key1: 1) [0] transform -> #f The second form doesn't set key0, so it gets the default value of #f. Is there something else I can do to get better output from trace? -Alan -- .i ko djuno fi le do sevzi _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
