in reply to Re (tilly) 1: DWIM Part Nineteen: Unary Operators in Void Context
in thread DWIM Part Nineteen: Unary Operators in Void Context
OTOH no less than Damian Conway is a big fan of customized versions of Perl
Though, you'll note that I always customize the syntax, never the semantics. And I always do it in such a way that you have to start the customized code with an explicit use Some::Module::Name directive.
I'm certainly not in favour of customizations that change semantics by stealth.
As for the original proposal to make built-ins modify their arg in a void context, I know that Larry has considered this and is still working through some of the problems with the idea. Like the fact that the same piece of code inside a sub can be in both void and non-void contexts when called from different points in the code (as others have pointed out in the thread).
Personally, if we see anything like this, I think it is far more likely that we'll see an explicit syntax for it. There's a strong analogy here to the proposal that operators automatically vectorize when given array arguments. Larry rejected that idea and came up with explicit hyperoperators instead. If he likes the idea of in-place versions of built-ins, I'd expect we'd see some new pseudo-operator to mark them as in-place.
From that perspective, the extension of $var =~ &whatever to mean $var = whatever $var does have some merit. Though it's still debatable whether it's worth the bother, given you can already so easily write:
sub apply (&@) { my $func = shift; $_ = $func->($_) foreach @_; } apply {lc} $var; apply {uc} $var1, $var2; apply {abs} @values; # etc.
Or in Perl 6:
sub apply (&func, *@args) { $_ = func($_) foreach @args; }
Or maybe even use an (as yet theoretical) "iterative superposition":
I just invented that notion on the spot, but it will definitely go into the next release of Quantum::Superpositions, and I'll also pitch it to Larry (along with any and all) for Perl 6.sub apply (&func, *@args) { each(@args) = func(each @args); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 3: DWIM Part Nineteen: Unary Operators in Void Context
by tilly (Archbishop) on Jan 01, 2002 at 07:46 UTC | |
by TheDamian (Vicar) on Jan 01, 2002 at 12:21 UTC |