On Fri, Dec 21, 2007 at 08:41:54AM -0800, Jonathan Lang wrote:
: I'm wondering if something similar could be done for optional
: arguments - something along the lines of "within the following block,
: assign value V to argument X of routine R by default." This would
: allow for a similar "factoring out" of repetitive flags. So instead
: of:
:
: say qq:!c" ... { ... } ...";
: say qq:!c" ... { ... } ...";
: say qq:!c" ... { ... } ...";
:
: and so on, you might do something like:
:
: with &qq :(c => false) {
: say "... { ... } ...";
: say "... { ... } ...";
: say "... { ... } ...";
: }
Hmm, well, qq isn't really a function, it's actually the name of
a sublanguage, as parsed by a macro.
: Or maybe it could be a pragma (which, by definition, lasts only until
: the end of the current scope):
:
: {
: use defaults { qq => :!c }
: say "... { ... } ...";
: say "... { ... } ...";
: say "... { ... } ...";
: }
I like to name pragmas by the construct they're controlling, so if
we took that approach, I'd probably make it something like:
{
use qq ':!c';
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}
: The core concept here is to allow the programmer to easily change the
: default behavior of a routine within a given scope so that he doesn't
: have to repeatedly override the default behavior every time it comes
: up.
:
: --
:
: Is this reasonable, or is this too much of a corner case to be worth the
effort?
Well, sure, but there's really no effort required at all, given you can
already do it (in theory) with:
{
my macro quote:<" "> { 'qq:!c' }
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}
Actually, the "my" is a bit redundant there; syntax changes from
macros are always lexically scoped. That includes imports of macros,
so if you made a module that contained:
my macro quote:<" "> is export(:DEFAULT) { 'qq:!c' }
then you could use it like this:
{
use Schwernlich;
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}
and it would be a lexically scoped language hack. With a slight
generalization it's the "use qq" pragma above. Welcome to Perl 6. :)
Larry