develooper Front page | perl.perl6.language | Postings from February 2002

RE: proposal: when-blocks, and binding $_

Thread Previous | Thread Next
From:
Brent Dax
Date:
February 26, 2002 14:16
Subject:
RE: proposal: when-blocks, and binding $_
Message ID:
FJELLKOPEAGHOOODKEDPKEDIDEAA.brentdax@cpan.org
Austin Hastings:
# --- Allison Randal <al@shadowed.net> wrote:
# > On Tue, Feb 26, 2002 at 01:26:41PM -0800, Austin Hastings wrote:
# > >
# > > Possibility B- when-blocks accept a -> operator, which if used
# > "naked"
# > > binds the current localizer to $_.
# >
# > I think if I had a choice between
# >
# > given $y -> $x {
# > 	when /a/ -> {...}
# > 	when /b/ -> {...}
# > 	...
# > }
# >
# > and
# >
# > given $y {
# > 	when /a/ {...}
# > 	when /b/ {...}
# > 	...
# > }
# >
# > I'd always prefer the second. Re-aliasing the aliased variable for
# > every
# > when block doesn't quite seem worth the effort.
#
# Which, then, would you like:
#
# To implicitly localize $_, losing access to an outer version,
# or to have to change between implicit and explicit operations?

That's easy to fix in one of two ways:

	for @A -> $y {
		for @B -> $x {
			...
		}
	}

or:

	for @A {
		my $y := $_;
		for @B -> $x {
			...
		}
	}

# for @A {
#   for @B -> $x {
#     when /a/ { s/x/y/; }
#   }
# }
#
# What should that do?

If you're too lazy to type the four characters in "->$y", too bad.

PS. Small nit in the way you reply: please put the text you're replying
to *above* your reply and intersperse your text with the text of the
message as appropriate.  I and most other people on the Perl 6 lists use
this style--it helps to provide context and remind people what the
discussion is about.  Even if your mailer arranges the text so that your
style is easier (as mine does), it takes only a few keystrokes per
message to reformat it.

--Brent Dax
brentdax@cpan.org
Parrot Configure pumpking, regex hacker, embedding coder, and boy genius

#define private public
    --Spotted in a C++ program just before a #include


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About