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":

sub apply (&func, *@args) { each(@args) = func(each @args); }
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.

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
    Actually I won't note that.

    I note instead that Quantum::Superpositions manages to achieve semantic effects which are quite different from the usual expectations of Perl programmers. Now while it is true that they are not beyond the range of possibility of the language (as is evidenced by the fact that you achieved them within Perl), I think that they are so far out of the norm for Perl that I see the result as a customization of Perl's semantics.

    But yes, you attempt some forms of sanity, and one of the ways this shows is that you arrange to get an explicit request for insanity before truly opening the floodgates...

      We obvious comprehend quite different meanings of the word "customize". To me, an extension to the language (such as Q::S) is not a customization, per se. A customization is something that changes the semantics of existing syntax.

      So, if you were going to call my bluff, it should probably have been over a module like Inline::Files, where I do change the semantics of an existing construct!

      Of course, you may well mean something quite different by "customization", in which case we're just arguing over (a different form of) semantics. ;-)