Whoops, just noticed this was sent to only me: I can duplicate your issue, in that the macro is hit, the debug code is quasi'd, but the resulting class doesn't seem to have a $.b.
Hitting the list to get more discussion on the right way to approach this particular problem. On Tue, Dec 17, 2013 at 10:02 AM, Richard Hainsworth <rnhainswo...@gmail.com > wrote: > Will, > > I'm not having much success. > > Here's a small test.p6 program. It compiles, but does not output what I'm > expecting, namely > > A.new(a => "0.984", b => 4 ) > > Instead, I get > > A.new(a => "0.984") > > test.p6 is > > use v6; > > constant DEBUG = True; > > macro include-debug ($code) { > if DEBUG { quasi { $code } } else { quasi {} } > } > > class A { > has $.a is rw = rand.fmt("%.3f"); > include-debug('has $.b is rw;'); > } > > my A $x .=new; > include-debug(' $x.b = 4; '); > $x.say; > > > <end program> > > In the 'true' section of the 'if' statement, I've tried > quasi { $code } > $code > quasi { {{{ $code }}} } > > All produce the same result. > What am I doing wrong? > > > Richard > > On 12/17/2013 02:25 AM, Will Coleda wrote: > > I would start with > http://strangelyconsistent.org/blog/macros-what-are-they-really for a way > to parse but not execute potentially expensive debug code. > > > > > On Sun, Dec 15, 2013 at 10:49 PM, Richard Hainsworth < > rnhainswo...@gmail.com> wrote: > >> What should be the perl6 idiom for handling debug code? >> >> I am writing a program that will be run with large values and take some >> time when it is clear that it is running correctly. >> >> In order to ensure that the program is correct, I have added code to >> generate and output intermediate results. I do not want this code to be >> compiled for the large values. At the same time, I don't want to eliminate >> the code in case the intermediate results will be needed again. I have >> previously handled this situation by commenting out the debug code, but >> this leads to problems when I want it back. >> >> My first thought was: >> >> constant DEBUG = True; >> >> BEGIN { if DEBUG { >> # code generating intermediate results >> } >> } >> >> But then this fails in this context >> >> class A { >> has $.a is rw; >> BEGIN { if DEBUG { >> has @.mem-metric; >> } >> } >> has $.b; >> # etc etc etc >> >> method reset { >> @.mem-metric = () >> } >> } >> >> I actually got " Null PMC access in find_method('mem-metric') " >> without a line number to indicate at what point the compilation got >> stopped, which indicates that this is a bug rather than a syntax error. >> >> However, I was wondering whether there was another way to achieve the >> same effect. Possible using POD as an extension of just commenting out the >> code? >> >> Regards >> Richard >> >> > > > -- > Will "Coke" Coleda > > > -- Will "Coke" Coleda