in reply to DWIM Part Nineteen: Unary Operators in Void Context

One argument for it is that you now have a more customized language to use that you can be more efficient with. Keep trying to do it, and your productivity will rise.

A big argument against it is that you have just raised the barrier for being able to exchange code with others. For instance if you get used to using this feature, then you may accidentally write and test something that will not work on anyone else's machine.

Your choice. But I happen to believe the tendancy to not customize local versions of Perl was a major factor in making CPAN be viable. OTOH no less than Damian Conway is a big fan of customized versions of Perl, and will cheerfully customize yours to speak Latin, Morse, and Klingon if given half a chance...

  • Comment on Re (tilly) 1: DWIM Part Nineteen: Unary Operators in Void Context

Replies are listed 'Best First'.
Re: Re (tilly) 1: DWIM Part Nineteen: Unary Operators in Void Context
by TheDamian (Vicar) on Dec 30, 2001 at 03:22 UTC
    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.
      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. ;-)