Re: $_ defaulting for mutating ops

2005-11-04 Thread Rob Kinyon
> $ perl -le '$u=1; ($y=$u*=5)++; print $y' > 6 It's interesting to note that this parse (due to precedence) as ($y=($u*=5))++, not (($y=$u)*=5)++ This is important for overloaded operators (which are going to become much easier to do in Perl6). The importance arises if Perl6 allows assignment to

Re: $_ defaulting for mutating ops

2005-11-04 Thread Michele Dondi
On Fri, 4 Nov 2005, TSa wrote: "derived" from C. But Perl's C<++> already allows an extended syntax wrt that of those other languages, that is: I'm not really sure, but I don't [snip] Actually I'm not sure if Perl 6 allows ($u *= 5)++; Since I wrote "already", I was referring to Perl5..

Re: $_ defaulting for mutating ops

2005-11-04 Thread TSa
HaloO, Michele Dondi wrote: And yes: there are lots of languages having (e.g.) a ++ operator, mostly "derived" from C. But Perl's C<++> already allows an extended syntax wrt that of those other languages, that is: I'm not really sure, but I don't think that in C you can do (the equivalent of)

Re: $_ defaulting for mutating ops

2005-11-04 Thread Michele Dondi
On Wed, 2 Nov 2005, Rob Kinyon wrote: I think the difference comes from the Principle of Least Surprise. The various operators being discussed in this thread are all operators which are in languages that have common use - C, C++, Java, the .Net stack, etc. Regexen and the various built-ins are g

Re: $_ defaulting for mutating ops

2005-11-04 Thread Michele Dondi
On Wed, 2 Nov 2005, John Williams wrote: surprises including operandless operators. Including mutating operandless operators. What is s/// after all? Or is there a good reason for an asymmetry between different classes of operators? Well, s/// is a term, for one thing. It is not so much an op

Re: syntax-variants, RPN (was: Re: $_ defaulting for mutating ops)

2005-11-03 Thread Rob Kinyon
On 11/3/05, Michele Dondi <[EMAIL PROTECTED]> wrote: > On Wed, 2 Nov 2005, Ruud H.G. van Tol wrote: > > >> http://www.nntp.perl.org/group/perl.perl6.language/17556 > > > > I understand that Perl6 allows blocks with changed/enhanced syntax, so > > it is or will become possible (to add it) as if it w

Re: $_ defaulting for mutating ops

2005-11-03 Thread Michele Dondi
On Thu, 3 Nov 2005, Sam Vilain wrote: That being said, there are probably other more pressing reasons that ops should not accept $_ as default; I would guess, for a start, it makes determining semantics very difficult. Does ++; mean &postfix:<++> or &prefix:<++> ? If we had it, I think we wo

Re: syntax-variants, RPN (was: Re: $_ defaulting for mutating ops)

2005-11-03 Thread Michele Dondi
On Wed, 2 Nov 2005, Ruud H.G. van Tol wrote: http://www.nntp.perl.org/group/perl.perl6.language/17556 I understand that Perl6 allows blocks with changed/enhanced syntax, so it is or will become possible (to add it) as if it was in the core language. Do I understand that right? Something as sim

Re: $_ defaulting for mutating ops

2005-11-02 Thread Juerd
Sam Vilain skribis 2005-11-03 11:01 (+1300): > Does ++; mean &postfix:<++> or &prefix:<++> ? I no longer think $_ defaulting for mutating ops is a good idea, but to answer your question, read the original post: all these would imply the LHS, so that makes ++ postfix. Juerd -- http://convolutio

Re: $_ defaulting for mutating ops

2005-11-02 Thread Sam Vilain
On Wed, 2005-11-02 at 09:03 -0500, Rob Kinyon wrote: > I think the difference comes from the Principle of Least Surprise. The > various operators being discussed in this thread are all operators > which are in languages that have common use - C, C++, Java, the .Net > stack, etc. Regexen and the var

Re: $_ defaulting for mutating ops

2005-11-02 Thread Sam Vilain
On Wed, 2005-11-02 at 11:46 -0700, John Williams wrote: > It is not so much an operator, as it is a subroutine with really strange > syntax, and the side-effect of changing the $_ variable. You need to use > an operator to get it to affect a different variable. operators _are_ subroutines. There

Re: $_ defaulting for mutating ops

2005-11-02 Thread John Williams
On Wed, 2 Nov 2005, Michele Dondi wrote: > On Fri, 28 Oct 2005, John Williams wrote: > > But IMHO the reduction in typing for this relatively minor issue is not > > really worth the surprise to newbies at seeing operandless operators. > > I don't buy that argument as newbies are already exposed to

syntax-variants, RPN (was: Re: $_ defaulting for mutating ops)

2005-11-02 Thread Ruud H.G. van Tol
Michele Dondi: > Ruud H.G. van Tol: >> Or RPN-like: >> >> $x #= 2* 1+ 3/; > > Being a big fan of RPN myself (and considering it quite natural), I'd > appreciate very much such a feature. I had asked myself about RPN > features in P6, albeit in a probably unreasonable fashion: > > http://www.nntp.

Re: $_ defaulting for mutating ops

2005-11-02 Thread Rob Kinyon
On 11/2/05, Michele Dondi <[EMAIL PROTECTED]> wrote: > On Fri, 28 Oct 2005, John Williams wrote: > > > But IMHO the reduction in typing for this relatively minor issue is not > > really worth the surprise to newbies at seeing operandless operators. > > I don't buy that argument as newbies are alrea

Re: $_ defaulting for mutating ops

2005-11-02 Thread Michele Dondi
On Fri, 28 Oct 2005, John Williams wrote: But IMHO the reduction in typing for this relatively minor issue is not really worth the surprise to newbies at seeing operandless operators. I don't buy that argument as newbies are already exposed to all sorts of surprises including operandless oper

Re: $_ defaulting for mutating ops

2005-11-02 Thread Michele Dondi
On Fri, 28 Oct 2005, Ruud H.G. van Tol wrote: Or RPN-like: $x #= 2* 1+ 3/; Being a big fan of RPN myself (and considering it quite natural), I'd appreciate very much such a feature. I had asked myself about RPN features in P6, albeit in a probably unreasonable fashion: http://www.nntp.pe

Re: $_ defaulting for mutating ops

2005-10-28 Thread Luke Palmer
On 10/28/05, Ruud H.G. van Tol <[EMAIL PROTECTED]> wrote: > John Williams: > > > ($x *=2) += 1; > > Or ($x *= 2) ++; > > Maybe the comma should be taught a new trick: > > $x *= 2, ++, /= 3; > > meaning > > $x = (($x * 2) + 1) / 3; > > Or RPN-like: > > $x #= 2* 1+ 3/; Oh, gee, why don't

Re: $_ defaulting for mutating ops

2005-10-28 Thread Ruud H.G. van Tol
John Williams: > ($x *=2) += 1; Or ($x *= 2) ++; Maybe the comma should be taught a new trick: $x *= 2, ++, /= 3; meaning $x = (($x * 2) + 1) / 3; Or RPN-like: $x #= 2* 1+ 3/; -- Grtz, Ruud

Re: $_ defaulting for mutating ops

2005-10-28 Thread Rob Kinyon
> But IMHO the reduction in typing for this relatively minor issue is not > really worth the surprise to newbies at seeing operandless operators. AMEN! Rob

Re: $_ defaulting for mutating ops

2005-10-28 Thread John Williams
On Tue, 25 Oct 2005, Juerd wrote: > For comparison, here is the same code snippet again. First with, and > then without explicit $_. > > With: > > given ($subject) -> $_ { > $_ ~~ s/foo/bar/; > $_++; > $_ x= 2; > $_ ~= "!"; > } > > Without: > > given ($su

Re: $_ defaulting for mutating ops

2005-10-25 Thread Larry Wall
On Tue, Oct 25, 2005 at 02:51:35PM +0200, Juerd wrote: : For comparison, here is the same code snippet again. First with, and : then without explicit $_. : : With: : : given ($subject) -> $_ { : $_ ~~ s/foo/bar/; : $_++; : $_ x= 2; : $_ ~= "!"; : } : : Wit

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Larry Wall
On Tue, Oct 25, 2005 at 05:26:32PM +0200, Juerd wrote: : Michele Dondi skribis 2005-10-25 17:17 (+0200): : > Hmmm... maybe you're right that $__ is too huffmanized (and hence : > confusing) but $OUTER::_ is somewhat too few... : : for (1..9) -> $n { # ought to be more than enough : e

Re: $_ defaulting for mutating ops

2005-10-25 Thread Juerd
Sebastian skribis 2005-10-25 9:17 (-0700): > > I think it'd be great if +=, ~=, +&=, ++, etc, could all assume $_ on > > their LHS when there is no obvious operand. > It'd be nice to have these, but is it something that can wait? I > wouldn't mind if more effort was spent on other pieces if this c

Re: $_ defaulting for mutating ops

2005-10-25 Thread Sebastian
> I think it'd be great if +=, ~=, +&=, ++, etc, could all assume $_ on > their LHS when there is no obvious operand. It'd be nice to have these, but is it something that can wait? I wouldn't mind if more effort was spent on other pieces if this can be easily done in the future - sebastian

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Michele Dondi
On Tue, 25 Oct 2005, Juerd wrote: for (1..9) -> $n { # ought to be more than enough eval qq[ macro prefix:<\$_$n> { "\${ "OUTER::" x $n }_" } ]; } And then you can use $_1 .. $_9. I think $_1 is much clearer than $__, but I think neither is needed in the standard

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Juerd
Michele Dondi skribis 2005-10-25 17:17 (+0200): > Hmmm... maybe you're right that $__ is too huffmanized (and hence > confusing) but $OUTER::_ is somewhat too few... for (1..9) -> $n { # ought to be more than enough eval qq[ macro prefix:<\$_$n> { "\${ "OUTER::" x $n }_"

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Mark Reed
On 2005-10-25 11:17 AM, "Michele Dondi" <[EMAIL PROTECTED]> wrote: >> I find $__ confusing, and prefer $OUTER::_, which already exists. > > Hmmm... maybe you're right that $__ is too huffmanized (and hence > confusing) but $OUTER::_ is somewhat too few... What's confusing about $__ is that it lo

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Michele Dondi
On Tue, 25 Oct 2005, Juerd wrote: Michele Dondi skribis 2005-10-25 17:05 (+0200): Now, one that I've sometimes desired is a "two level" $_, i.e. a variable, say, $__ referring to the _second next_ enclosing lexical scope. I am aware that in this vein one may ask a third analogue and so on, but

Re: Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Juerd
Michele Dondi skribis 2005-10-25 17:05 (+0200): > Now, one that I've sometimes desired is a "two level" $_, i.e. a variable, > say, $__ referring to the _second next_ enclosing lexical scope. I am > aware that in this vein one may ask a third analogue and so on, but let's > face it: $_ already c

Pronouns ["Re: $_ defaulting for mutating ops"]

2005-10-25 Thread Michele Dondi
On Tue, 25 Oct 2005, Juerd wrote: Reducing line noise isn't my goal, though. I feel that the implicit defaulting to $_ makes Perl a more natural and elegant language, and would like this principle being extended to these operators. Indeed, both the implicit defaulting to $_ AND the availabilit

Re: $_ defaulting for mutating ops

2005-10-25 Thread Michele Dondi
On Tue, 25 Oct 2005, Rob Kinyon wrote: On 10/25/05, Juerd <[EMAIL PROTECTED]> wrote: I think it'd be great if +=, ~=, +&=, ++, etc, could all assume $_ on their LHS when there is no obvious operand. [snip] Especially bare ++ would be useful, I think. Did you post this specifically to anti-a

Re: $_ defaulting for mutating ops

2005-10-25 Thread Juerd
Rob Kinyon skribis 2005-10-25 8:37 (-0400): > Did you post this specifically to anti-address the fear that P6 will > be more line-noise-ish than P5? :-p No. Leaving out $_ is one of the important features in *reducing* line noise. We're all very used to seeing it, but to most people it is just tw

Re: $_ defaulting for mutating ops

2005-10-25 Thread Rob Kinyon
On 10/25/05, Juerd <[EMAIL PROTECTED]> wrote: > I think it'd be great if +=, ~=, +&=, ++, etc, could all assume $_ on > their LHS when there is no obvious operand. > > This clashes with &prefix:<=>, but that's nothing a space cannot fix. > Same for lvalue subs called x or xx (or X or XX). > > m