statement modifiers for setting variables

3 views
Skip to first unread message

Dave Whipp

unread,
Apr 18, 2005, 9:01:48 PM4/18/05
to perl6-l...@perl.org
The following is legal perl:

print "$a $b $c" if ($a,$b,$c)=(1,2,3);

This prints "1 2 3", but the definitions obviously aren't scoped to the
modified statement. And a C<my> in the modifier is a bit too late.

Any reason to [not] add a C<where> statement modifier which restricts
the scope of the declarations? Sure its redundant, but so are all
statement modifiers. Sometimes its good to factor things out and express
them later, rather than earlier. It lets us focus on the important
things first:

print "$a $b $c" where ($a,$b,$c)=(1,2,3);

(in this case, we could use printf to to the factoring, but that's not a
general solution).

Larry Wall

unread,
Apr 19, 2005, 11:07:59 AM4/19/05
to perl6-l...@perl.org
On Mon, Apr 18, 2005 at 06:01:48PM -0700, Dave Whipp wrote:
: The following is legal perl:

:
: print "$a $b $c" if ($a,$b,$c)=(1,2,3);
:
: This prints "1 2 3", but the definitions obviously aren't scoped to the
: modified statement. And a C<my> in the modifier is a bit too late.
:
: Any reason to [not] add a C<where> statement modifier which restricts
: the scope of the declarations?

Already used "where" for subtype constraints.

: Sure its redundant, but so are all

: statement modifiers. Sometimes its good to factor things out and express
: them later, rather than earlier. It lets us focus on the important
: things first:
:
: print "$a $b $c" where ($a,$b,$c)=(1,2,3);
:
: (in this case, we could use printf to to the factoring, but that's not a
: general solution).

Okay, here's a slightly more general solution:

{ print "$^a $^b $^c" }.(1,2,3);

Larry

Reply all
Reply to author
Forward
0 new messages