Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

Dismiss

1 view

Skip to first unread message

Sep 12, 2006, 10:51:14 AM9/12/06

to perl6-l...@perl.org

Author: larry

Date: Tue Sep 12 07:51:14 2006

New Revision: 11965

Date: Tue Sep 12 07:51:14 2006

New Revision: 11965

Modified:

doc/trunk/design/syn/S03.pod

Log:

Allow [=] and [+=].

Modified: doc/trunk/design/syn/S03.pod

==============================================================================

--- doc/trunk/design/syn/S03.pod (original)

+++ doc/trunk/design/syn/S03.pod Tue Sep 12 07:51:14 2006

@@ -12,9 +12,9 @@

Maintainer: Larry Wall <la...@wall.org>

Date: 8 Mar 2004

- Last Modified: 4 Sep 2006

+ Last Modified: 12 Sep 2006

Number: 3

- Version: 57

+ Version: 58

=head1 Changes to Perl 5 operators

@@ -802,8 +802,8 @@

=head2 Reduction operators

The final metaoperator in Perl 6 is the reduction operator. Any

-infix operator (except for non-associating operators and assignment

-operators) can be surrounded by square brackets in term position to

+infix operator (except for non-associating operators)

+can be surrounded by square brackets in term position to

create a list operator that reduces using that operation:

[+] 1, 2, 3; # 1 + 2 + 3 = 6

@@ -980,6 +980,26 @@

@args = (\%a,'foo','bar');

$x = [dehash] @args;

+Likewise, from the fact that list context flattens inner arrays and

+lists, it follows that a reduced assignment does no special syntactic

+dwimmery, and hence only scalar assigments are supported. Therefore

+

+ [=] $x, @y, $z, 0

+ [+=] $x, @y, $z, 1

+

+are equivalent to

+

+ $x = @y[0] = @y[1] = @y[2] ... @y[-1] = $z = 0

+ $x += @y[0] += @y[1] += @y[2] ... @y[-1] += $z += 1

+

+rather than

+

+ $x = @y = $z = 0;

+ $x += @y += $z += 1;

+

+(And, in fact, the latter are already easy to express anyway,

+and more obviously nonsensical.)

+

A reduce operator returns only a scalar result regardless of context.

(Even C<[,]> returns a single C<Capture> object which is then spliced

into the outer argument list.) To return all intermediate results,

Sep 12, 2006, 12:16:26 PM9/12/06

to perl6-l...@perl.org

larry schreef:

> +Likewise, from the fact that list context flattens inner arrays and

> +lists, it follows that a reduced assignment does no special syntactic

> +dwimmery, and hence only scalar assigments are supported. Therefore

> +

> + [=] $x, @y, $z, 0

> + [+=] $x, @y, $z, 1

> +

> +are equivalent to

> +

> + $x = @y[0] = @y[1] = @y[2] ... @y[-1] = $z = 0

> + $x += @y[0] += @y[1] += @y[2] ... @y[-1] += $z += 1

I assume that

[=] $x, @y

is equivalent to

$x = @y[0] = @y[1] = @y[2] ... @y[-2] = y[-1]

then. Or is a scalar required at the end?

--

Affijn, Ruud

"Gewoon is een tijger."

Sep 12, 2006, 12:48:53 PM9/12/06

to perl6-l...@perl.org

On Tue, Sep 12, 2006 at 06:16:26PM +0200, Dr.Ruud wrote:

: larry schreef:

:

: > +Likewise, from the fact that list context flattens inner arrays and

: > +lists, it follows that a reduced assignment does no special syntactic

: > +dwimmery, and hence only scalar assigments are supported. Therefore

: > +

: > + [=] $x, @y, $z, 0

: > + [+=] $x, @y, $z, 1

: > +

: > +are equivalent to

: > +

: > + $x = @y[0] = @y[1] = @y[2] ... @y[-1] = $z = 0

: > + $x += @y[0] += @y[1] += @y[2] ... @y[-1] += $z += 1

:

: I assume that

:

: [=] $x, @y

:

: is equivalent to

:

: $x = @y[0] = @y[1] = @y[2] ... @y[-2] = y[-1]

:

: then.

: larry schreef:

:

: > +Likewise, from the fact that list context flattens inner arrays and

: > +lists, it follows that a reduced assignment does no special syntactic

: > +dwimmery, and hence only scalar assigments are supported. Therefore

: > +

: > + [=] $x, @y, $z, 0

: > + [+=] $x, @y, $z, 1

: > +

: > +are equivalent to

: > +

: > + $x = @y[0] = @y[1] = @y[2] ... @y[-1] = $z = 0

: > + $x += @y[0] += @y[1] += @y[2] ... @y[-1] += $z += 1

:

: I assume that

:

: [=] $x, @y

:

: is equivalent to

:

: $x = @y[0] = @y[1] = @y[2] ... @y[-2] = y[-1]

:

: then.

Yes.

: Or is a scalar required at the end?

Yes, but @y[-1] is a perfectly fine scalar.

Larry

Sep 12, 2006, 4:30:39 PM9/12/06

to perl6-l...@perl.org

Larry Wall schreef:

> Dr.Ruud:

>> larry:

> Dr.Ruud:

>> larry:

>>> +Likewise, from the fact that list context flattens inner arrays and

>>> +lists, it follows that a reduced assignment does no special

>>> syntactic +dwimmery, and hence only scalar assigments are

>>> supported. Therefore +

>>> + [=] $x, @y, $z, 0

>>> + [+=] $x, @y, $z, 1

>>> +

>>> +are equivalent to

>>> +

>>> + $x = @y[0] = @y[1] = @y[2] ... @y[-1] = $z = 0

>>> + $x += @y[0] += @y[1] += @y[2] ... @y[-1] += $z += 1

>>

>> I assume that

>>

>> [=] $x, @y

>>

>> is equivalent to

>>

>> $x = @y[0] = @y[1] = @y[2] ... @y[-2] = @y[-1] [_edited_]

>>

>> then.

>

> Yes.

>> Or is a scalar required at the end?

>

> Yes, but @y[-1] is a perfectly fine scalar.

Yes, but I meant it more at a 'source-filter' level.

Suppose that you need to set everything to @y[0],

I think you can code

[=] $x, @y, @y[0] # looks clean, but does extra,

# but maybe in an efficient order

[=] $x, @y[1 .. *], @y[0] # hand-optimized?

[=] $x, @y.reverse # or does .reverse copy?

[=] $x, @y[reverse 0 .. *] # hi-brow?

and what not. (Pardon my French.)

0 new messages

Search

Clear search

Close search

Google apps

Main menu