> Date: Thu, 09 Jan 2003 19:55:20 -0500 > From: John Siracusa <[EMAIL PROTECTED]> > > Has there been any discussion of how to create code in Perl 6 that's there > under some conditions, but not there under others? I'm thinking of the > spiritual equivalent of #ifdef, only Perlish. > > In Perl 5, there were many attempts to use such a feature for debugging and > assertions. What everyone wanted to do was write code like this: > > debug("Doing foo with $bar and $baz"); > foo($bar, $baz); > And then have the entire call to debug() just plain disappear when the > program was run with a certain flag, or when a particular constant was set, > or whatever. The closest we got in Perl 5, AFAIK, was stuff this: > > use constant DEBUG => 0; > ... > debug("Doing foo with $bar and $baz") if DEBUG; > foo($bar, $baz);
Well, I just do: sub debug { print STDERR shift, "\n" if DEBUG; } And hopefully (I don't know P5 internals so well) that optimizes to a no-op so there's not even a function call there. But it's a negligible overhead anyway. > But all those "if DEBUG"s or "DEBUG &&"s were a pain. So I'm wondering what > the solution will be in Perl 6. Not that C code is devoid of C<#ifdef>s everywhere there's conditional code.... I don't see how you could do much without actually labeling what you wanted to disappear. You could always use: sub debug(&code) { &code() if DEBUG; } For a more versatile and readable solution. I'm not sure what could be more concise than that. Luke