Google групе више не подржавају нове Usenet постове ни праћења. Претходни садржај остаје видљив.

pugs: rw block parameters

5 прегледа
Пређи на прву непрочитану поруку

Mark J. Reed

непрочитано,
23. 8. 2006. 17:01:4323.8.06.
– perl6-c...@perl.org
Sorry if this is a known question, but I didn't see it mentioned in the
recent archive or FAQ.

for ($a, $b) { $_ = ... }

gives me a "Can't modify constant item: VRef <Scalar>". Making it
explicitly rw doesn't help:

for ($a, $b) -> $x is rw { $x = ... }

Is this a "haven't gotten around to rw parameters in blocks yet" or a
regression?


--
Mark J. Reed <mark...@mail.com>

Larry Wall

непрочитано,
24. 8. 2006. 14:54:4924.8.06.
– perl6-c...@perl.org
On Wed, Aug 23, 2006 at 05:01:43PM -0400, Mark J. Reed wrote:
: Sorry if this is a known question, but I didn't see it mentioned in the

: recent archive or FAQ.
:
: for ($a, $b) { $_ = ... }
:
: gives me a "Can't modify constant item: VRef <Scalar>".

Which is correct as the default.

: Making it explicitly rw doesn't help:


:
: for ($a, $b) -> $x is rw { $x = ... }
:
: Is this a "haven't gotten around to rw parameters in blocks yet" or a
: regression?

Not implemented, I think, but could be a regression. In any event, not
right currently.

Larry

Mark J. Reed

непрочитано,
24. 8. 2006. 15:11:1024.8.06.
– perl6-c...@perl.org
On 8/24/06, Larry Wall <la...@wall.org> wrote:
> On Wed, Aug 23, 2006 at 05:01:43PM -0400, Mark J. Reed wrote:
> : Sorry if this is a known question, but I didn't see it mentioned in the
> : recent archive or FAQ.
> :
> : for ($a, $b) { $_ = ... }
> :
> : gives me a "Can't modify constant item: VRef <Scalar>".
>
> Which is correct as the default.

Not according to the spec. S04 says:

> If you rely on C<$_> as the implicit parameter to a block,
> then [it] is considered read/write by default. That is,
> the construct:
>
> for @foo {...}
>
> is actually short for:
>
> for @foo -> $_ is rw {...}

Larry Wall

непрочитано,
24. 8. 2006. 16:37:3824.8.06.
– perl6-c...@perl.org
On Thu, Aug 24, 2006 at 03:11:10PM -0400, Mark J. Reed wrote:
: On 8/24/06, Larry Wall <la...@wall.org> wrote:
: >On Wed, Aug 23, 2006 at 05:01:43PM -0400, Mark J. Reed wrote:
: >: Sorry if this is a known question, but I didn't see it mentioned in the
: >: recent archive or FAQ.
: >:
: >: for ($a, $b) { $_ = ... }
: >:
: >: gives me a "Can't modify constant item: VRef <Scalar>".
: >
: >Which is correct as the default.
:
: Not according to the spec. S04 says:

Oops, sorry, was confusing implicit $_ with explicit ->$_. You are correct.

Larry

Audrey Tang

непрочитано,
24. 8. 2006. 20:22:0124.8.06.
– Mark J. Reed, perl6-c...@perl.org

在 2006/8/25 上午 4:37 時,Larry Wall 寫到:

And indeed I confused it as well. Fixed as of r12675.

Mark, can you add a test to t/statements/for.t? A commit bit is on
its way to your inbox. :-)

Thanks!
Audrey

PGP.sig

Mark J. Reed

непрочитано,
24. 8. 2006. 23:52:3624.8.06.
– Audrey Tang, perl6-c...@perl.org
On 8/24/06, Audrey Tang <aud...@audreyt.org> wrote:
> Mark, can you add a test to t/statements/for.t? A commit bit is on
> its way to your inbox. :-)

Happily, as soon as I receive it.

Upon further investigation I see that the problem is not rw parameters
per se, but the ability to pass individual lvalue items into them.

That is, this works (and a test for it is already in for.t):

my @a = (0..2); for @a { $_++ }
say @a; # 1,2,3

But this dies with the "Can't modify constant item: VRef <Scalar>" message:

my ($a,$b,$c) = 0..2; for ($a,$b,$c) { $_++; }

That may be what you fixed; I haven't built r12675 yet to see. But
it's not what I thought the problem was. :)

Mark J. Reed

непрочитано,
25. 8. 2006. 15:42:5225.8.06.
– Audrey Tang, perl6-c...@perl.org
On 8/24/06, Audrey Tang <aud...@audreyt.org> wrote:
> Mark, can you add a test to t/statements/for.t? A commit bit is on
> its way to your inbox. :-)

Done. Tests 37 (implicit "rw $_") and 38 (explicit "-> $x is rw")
add to for.t as of r12968.

0 нових порука