I'm thinking aloud here, so please bear with me.
A number of languages have a "with ..." construct that's intended to
cut down on repetitive typing, by factoring the invocant out of every
method call. Perl 6 also has this, in the form of "given ...":
given $foo.bar.baz {
.dothis();
.dothat();
.doanother();
}
(same as)
$foo.bar.baz.dothis();
$foo.bar.baz.dothat();
$foo.bar.baz.doanother();
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 "... { ... } ...";
}
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 "... { ... } ...";
}
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?
--
Jonathan "Dataweaver" Lang