Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Perl 6's for() signature
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  22 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Siracusa  
View profile  
 More options Jul 31 2003, 11:48 am
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Thu, 31 Jul 2003 11:37:52 -0400
Local: Thurs, Jul 31 2003 11:37 am
Subject: Perl 6's for() signature
 From an old summary:

http://www.perl.com/pub/a/2003/04/p6pdigest/20030427.html?page=2

 > Paul Hodges took a crack at implementing for as a subroutine and came
up with
 > something that didn't look too insane. Luke Palmer added a refinement
allowing
 > for n at a time looping. However, for reasons that I can't quite put
my finger
 > on, I'm not quite sure that either method has got the sub signature
quite
 > right, and I'm not entirely sure how you would express for's
signature as a
 > Perl 6 signature anyway. Answers on a mailing list please.

Did this ever get resolved to anyone's satisfaction?  While reading
EX6, I found myself wonder exactly what for() would look like in Perl 6
code...

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Jul 31 2003, 12:48 pm
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: 31 Jul 2003 10:05:05 -0600
Local: Thurs, Jul 31 2003 12:05 pm
Subject: Re: Perl 6's for() signature

Well, I don't think it's possible, actually.  There's a flattening
list context at the beginning (implying a sugary drink from 7 eleven),
followed by a code block.  But, as we know, slurpy arrays can only
come at the end of positional parameters.

But, assuming that is possible, here's C<for> in its entirety:

    sub for (*@list, &block) {
        while @list {
            block( *...@list.splice(0, &block.arity) );
        }
    }

That's not handling NEXT blocks, et al.  But I think that's just a
matter of putting &block.NEXT(), &c. in the appropriate places.

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jul 31 2003, 12:49 pm
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Thu, 31 Jul 2003 12:35:19 -0400
Local: Thurs, Jul 31 2003 12:35 pm
Subject: Re: Perl 6's for() signature

On Thursday, July 31, 2003, at 12:05 PM, Luke Palmer wrote:
> Well, I don't think it's possible, actually.  There's a flattening
> list context at the beginning (implying a sugary drink from 7 eleven),
> followed by a code block.  But, as we know, slurpy arrays can only
> come at the end of positional parameters.

Right, which is why I couldn't get my head around it.  But EX6 says:

"an important goal of Perl 6 is to make the language powerful enough to
natively implement all its own built-ins"

Does "built-ins" just mean "subs" like split(), or does it also include
control structures like if() and for()?

> But, assuming that is possible, here's C<for> in its entirety:

>     sub for (*@list, &block) {
>         while @list {
>             block( *...@list.splice(0, &block.arity) );
>         }
>     }

Maybe for() does some magic with "is parsed" and the various Perl 6
grammar rule regexes?

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rod Adams  
View profile  
 More options Jul 31 2003, 1:00 pm
Newsgroups: perl.perl6.language
From: r...@rodadams.net (Rod Adams)
Date: Thu, 31 Jul 2003 11:56:16 -0500
Local: Thurs, Jul 31 2003 12:56 pm
Subject: Re: Perl 6's for() signature
At 10:05 AM 7/31/2003 -0600, Luke Palmer wrote:

>Well, I don't think it's possible, actually.  There's a flattening
>list context at the beginning (implying a sugary drink from 7 eleven),
>followed by a code block.  But, as we know, slurpy arrays can only
>come at the end of positional parameters.

Anyone but me feel the need for non-greedy slurpy arrays? similar to
non-greedy RE matches?
Then we could do:

sub for (*?@data, &block) {...}

Proposed behavior of *?@ : All Arguement to Parameter mapping left of it
are processed Left to Right. Once seen, the mapping starts over right to
left. Everything remaining is slurpable.

Yes, it's more expensive to use, just like the RE version, but shouldn't
impact performance _too_ bad when it's not, since the behavior will be
detectable at compile time.

Thoughts?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Worthington  
View profile  
 More options Jul 31 2003, 3:49 pm
Newsgroups: perl.perl6.language
From: jonat...@jwcs.net (Jonathan Worthington)
Date: Thu, 31 Jul 2003 20:01:50 +0100
Local: Thurs, Jul 31 2003 3:01 pm
Subject: Re: Perl 6's for() signature

Doing something like that was what came to my mind right away when I read
what Luke put too...  It "feels right" to me, though I don't know that
counts for much.  :-)

Jonathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rod Adams  
View profile  
 More options Jul 31 2003, 3:49 pm
Newsgroups: perl.perl6.language
From: r...@rodadams.net (Rod Adams)
Date: Thu, 31 Jul 2003 14:13:27 -0500
Local: Thurs, Jul 31 2003 3:13 pm
Subject: RE: Perl 6's for() signature
At 01:29 PM 7/31/2003 -0400, Hanson, Rob wrote:

> > Anyone but me feel the need for non-greedy
> > slurpy arrays? similar to non-greedy RE matches?

>I definately like the idea of having something like that.  It probably
>wouldn't be used much, but it is nice to have the option.

>One thing though, can't you accomplish the same thing by slurping
>everything, then poping the block off of the array?

One could do most of the stuff in P6 parameters with P5's @_. But as Damian
showed at the end of E6, it can quickly grow to a nightmare, and making it
nicer is what P6 is all about.

-- Rod


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Hanson  
View profile  
 More options Jul 31 2003, 4:49 pm
Newsgroups: perl.perl6.language
From: rhan...@aptegrity.com (Rob Hanson)
Date: Thu, 31 Jul 2003 13:29:33 -0400
Local: Thurs, Jul 31 2003 1:29 pm
Subject: RE: Perl 6's for() signature

> Anyone but me feel the need for non-greedy
> slurpy arrays? similar to non-greedy RE matches?

I definately like the idea of having something like that.  It probably
wouldn't be used much, but it is nice to have the option.

One thing though, can't you accomplish the same thing by slurping
everything, then poping the block off of the array?

Rob


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Attriel  
View profile  
 More options Jul 31 2003, 6:49 pm
Newsgroups: perl.perl6.language
From: attr...@d20boards.net (Attriel)
Date: Thu, 31 Jul 2003 18:41:36 -0400 (EDT)
Local: Thurs, Jul 31 2003 6:41 pm
Subject: Re: Perl 6's for() signature

> Anyone but me feel the need for non-greedy slurpy arrays? similar to
> non-greedy RE matches?
> Then we could do:

> sub for (*?@data, &block) {...}

> Proposed behavior of *?@ : All Arguement to Parameter mapping left of it
> are processed Left to Right. Once seen, the mapping starts over right to
> left. Everything remaining is slurpable.

With obvious restrictions on "no other slurpy/semi-slurpy arrays" in the
param list, b/c that would make things go insane, IMHO.  Although, I guess
with typing, you could do splits on the typed params between, and assuming
there was no ambiguity ...

Ow, my head hurts now :o

--attriel


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Gottman  
View profile  
 More options Jul 31 2003, 7:48 pm
Newsgroups: perl.perl6.language
From: jgott...@carolina.rr.com (Joe Gottman)
Date: Thu, 31 Jul 2003 19:35:54 -0400
Local: Thurs, Jul 31 2003 7:35 pm
Subject: Re: Perl 6's for() signature


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Abhijit A. Mahabal  
View profile  
 More options Aug 1 2003, 11:49 am
Newsgroups: perl.perl6.language
From: amaha...@cs.indiana.edu (Abhijit A. Mahabal)
Date: Fri, 1 Aug 2003 10:42:37 -0500 (EST)
Local: Fri, Aug 1 2003 11:42 am
Subject: Re: Perl 6's for() signature

r...@rodadams.net (Rod Adams) wrote in message
> Proposed behavior of *?@ : All Arguement to Parameter mapping left of it
> are processed Left to Right. Once seen, the mapping starts over right to
> left. Everything remaining is slurpable.

> Yes, it's more expensive to use, just like the RE version, but shouldn't
> impact performance _too_ bad when it's not, since the behavior will be
> detectable at compile time.

> Thoughts?

There is another problem beyond efficiency: the P6 list semantics is lazy.

The following is valid P6, AFAIK:

for 1 .. Inf {
  print $_;
  last when 10;

}

And then most of the proposed methods (including popping off *@_) would
not work.

There is another problem that I see with a user defined my_for. We want to
be able to write

my_for 1 .. 5 { something }

and not have to write:

my_for 1 .. 5 {something };

What is bothering me is the following: If we have a sub with the
signature:
  sub very_complicated(Int $x, Code *@slurped)

how would the following get parsed:

very_complicated 7 { print "Hello," } { print " world!"}
# Those were the 3 args I wanted to pass
# and the next one is outside the call
sub next_routine {...}

It seems to me, then, that calls to user defined subs will need to end
with a semi-colon.

Abhi

Abhijit A. Mahabal                       Home: 520 N. Grant St, Apt #2
Graduate Student,                              Bloomington IN 47408
Dept of Cog Sci and Computer Science,          812 331 2286
Indiana University                       Off:  LH301I; 812 855 8898


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Aug 1 2003, 12:48 pm
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: 01 Aug 2003 10:21:35 -0600
Local: Fri, Aug 1 2003 12:21 pm
Subject: Re: Perl 6's for() signature

No, popping at least would work.  I can assure you of that.

Semicolon syntax shortcuts are still up in the air.  People constantly
get tripped up on whether or not to use a semicolon after whatever
kind of block.  So, there's going to be some rule which will allow you
to omit them...

As of A4, "a } on a line by itself gets an implicit semicolon added,
if syntactically valid".  But the rules might need to be a bit more
complex.  We'll see.

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damian Conway  
View profile  
 More options Aug 1 2003, 5:48 pm
Newsgroups: perl.perl6.language
From: dam...@conway.org (Damian Conway)
Date: Sat, 02 Aug 2003 07:23:06 +1000
Local: Fri, Aug 1 2003 5:23 pm
Subject: Re: Perl 6's for() signature
FWIW, we're aware of the problem.

I posed this very question to Larry a few months back, when I was writing E6.
We're still mulling over the correct answer. The last thought on the problem
that Larry's shared with me was that there may need to be a special case for
allowing a single &block parameter after the slurpy (which would then be
popped off the parsed arg list before slurpification).

I don't think either Larry or I thinks that's ideal, so we'll probably keep
working towards a better (more general) solution to the problem.

Damian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Cozens  
View profile  
 More options Aug 1 2003, 6:48 pm
Newsgroups: perl.perl6.language
From: si...@simon-cozens.org (Simon Cozens)
Date: Fri, 01 Aug 2003 23:01:15 +0100
Local: Fri, Aug 1 2003 6:01 pm
Subject: Re: Perl 6's for() signature

dam...@conway.org (Damian Conway) writes:
> The last thought on the problem that Larry's shared with me was that there
> may need to be a special case for allowing a single &block parameter after
> the slurpy

And the Rubyometer creeps up another few notches...

(Gosh, you'd almost think that Matz had already thought through some of these
issues, wouldn't you? ;)

--
Will your long-winded speeches never end?
What ails you that you keep on arguing?
                -- Job 16:3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Aug 1 2003, 9:48 pm
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Fri, 1 Aug 2003 18:02:17 -0700
Local: Fri, Aug 1 2003 9:02 pm
Subject: Re: Perl 6's for() signature
On Fri, Aug 01, 2003 at 11:01:15PM +0100, Simon Cozens wrote:

: dam...@conway.org (Damian Conway) writes:
: > The last thought on the problem that Larry's shared with me was that there
: > may need to be a special case for allowing a single &block parameter after
: > the slurpy
:
: And the Rubyometer creeps up another few notches...

It's long been planned to allow blocks anywhere in the signature,
particularly at the end, because of endweight considerations.  It's
been on my Perl 5 wish list since long before I ever heard of Ruby.
In fact, the first thing I thought when I saw how Ruby did it was,
"Gee, why did he restrict it to only be the last thing?"  In Ruby
it's a special case syntax.  We're making a general capability to put
the block anywhere in the argument list.  If that makes Perl more
like Ruby, so be it.  But Perl is not terribly worried about where
it fits on the Rubyometer.  Ruby will need to worry about where it
fits on the Perlometer.

: (Gosh, you'd almost think that Matz had already thought through some of these
: issues, wouldn't you? ;)

Certainly Matz thought about some of these issues.  Whether he would
claim to have thought them "through" is another matter.  There are
many throughways, and they don't all lead the same place.  It's easy
to tunnel into a false minimum and think you're "through".

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonadab The Unsightly One  
View profile  
 More options Aug 9 2003, 12:48 am
Newsgroups: perl.perl6.language
From: jona...@bright.net (Jonadab The Unsightly One)
Date: 09 Aug 2003 00:26:45 -0400
Local: Sat, Aug 9 2003 12:26 am
Subject: Re: Perl 6's for() signature
"Abhijit A. Mahabal" <amaha...@cs.indiana.edu> writes:

> There is another problem beyond efficiency: the P6 list semantics is lazy.

> The following is valid P6, AFAIK:

> for 1 .. Inf {
>   print $_;
>   last when 10;
> }

Yeah, but that's a foreach loop, despite the fact that "foreach" is
spelled "for" in your example.  foreach loops have a different
signature from for loops.  (P6 does make it possible to have two
routines with the same name that differ by signature, right?  ISTR
seeing something about that in one of the Apocalypses[1].)

> And then most of the proposed methods (including popping off *@_)
> would not work.

foreach loops take their only code block in the braces; you don't have
the code block inside the parens to worry about in that case, like you
would in a for loop.  Thus, foreach loops are no harder to implement
than while or if, signature-wise.

> my_for 1 .. 5 { something }

> and not have to write:

> my_for 1 .. 5 {something };

Ah, that's another matter, but you need that to implement while and if
as well.  Methinks that a signature should be able to call for a code
block in braces, and when it's called the signature after that code
block should be optional.  (And it needs to be optional whether the
code block is the last thing in the signature or not; else, how would
one implement map and grep and sort?)

A question I haven't fully thought through:  should a closing brace
_ever_ need to be followed by a semicolon?  Because, if not, then we
could do this...

my $foo = sub { do_stuff() } # <-- Note no semicolon..
my $baz = {
   my @bar;
   more_stuff(@bar)
   yetmorestuff(@bar)
   \@bar }                   # <-- Here also.

Would that have any nasty consequences I haven't thought about?

---

[1] I _think_ that's the right plural.

    *apocalupt + s + es => apocalupses, transliterated apocalypses.
    But my third declension is a little rusty and I'm not certain
    about that first s being added to the root to form the noun stem.

    It's a sufficiently unusal word imported to English recently
    enough that the plural would be formed like in the original
    language, yes?  But then why isn't the singular "apocalypsis"?

    Fooey, English is weird, let's stick with Perl.

--
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonadab The Unsightly One  
View profile  
 More options Aug 9 2003, 12:48 am
Newsgroups: perl.perl6.language
From: jona...@bright.net (Jonadab The Unsightly One)
Date: 09 Aug 2003 00:27:39 -0400
Local: Sat, Aug 9 2003 12:27 am
Subject: Re: Perl 6's for() signature

John Siracusa <sirac...@mindspring.com> writes:
> Did this ever get resolved to anyone's satisfaction?  While reading
> EX6, I found myself wonder exactly what for() would look like in
> Perl 6 code...

A for loop[1] is basically syntax sugar for a while loop.  In general,
where foo, bar, baz, and quux are expressions, the following are equivalent:

for (foo; bar; baz) { quux }
foo; while (bar) { quux; baz }

If Perl6 has enough syntax-sugar ability to let you turn the former
into the latter, then you don't need to worry about for's signature.

[1]  Of course I mean a C-style for loop.

--
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Aug 9 2003, 1:49 am
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: 08 Aug 2003 23:23:05 -0600
Local: Sat, Aug 9 2003 1:23 am
Subject: Re: Perl 6's for() signature

Yes, it's possible to have two routines with the same name which
differ by signature... however, in Perl 6, C<for> has only one
signature, and it's the one above.  The C<for> loop you are thinking
of is spelled C<loop>, and that's an obvious candidate for C<is
parsed>, because it's so funky.

> > And then most of the proposed methods (including popping off *@_)
> > would not work.

> foreach loops take their only code block in the braces; you don't have
> the code block inside the parens to worry about in that case, like you
> would in a for loop.  Thus, foreach loops are no harder to implement
> than while or if, signature-wise.

To the contrary, C<while> and C<if> take only a single expression in
scalar context, whereas C<for> takes a list in flattening list
context.  This is the trouble, because you need flattening list
context followed by a different, C<Code> context.  And that's not
allowed by A6 rules.

> > my_for 1 .. 5 { something }

> > and not have to write:

> > my_for 1 .. 5 {something };

> Ah, that's another matter, but you need that to implement while and if
> as well.  Methinks that a signature should be able to call for a code
> block in braces, and when it's called the signature after that code
> block should be optional.

You mean s:2nd/signature/semicolon/ ?

> (And it needs to be optional whether the code block is the last
> thing in the signature or not; else, how would one implement map and
> grep and sort?)

Because commas are always optional around a code block, no matter
where it appears.  This may well be generalized to semicolons, but
AFAIK, this is not the plan (yet).

> A question I haven't fully thought through:  should a closing brace
> _ever_ need to be followed by a semicolon?  Because, if not, then we
> could do this...

> my $foo = sub { do_stuff() } # <-- Note no semicolon..
> my $baz = {
>    my @bar;
>    more_stuff(@bar)
>    yetmorestuff(@bar)
>    \@bar }                   # <-- Here also.

> Would that have any nasty consequences I haven't thought about?

This has already been discussed at length.  The answer is "um". :-)

So far documented, the semicolon is only optional when the closing
brace is the only thing on the line.  Don't worry, Larry's got a
handle on this one, and I don't think it needs further discussion.

[snip]

>     Fooey, English is weird, let's stick with Perl.

> --
> $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
> split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/

Hmm, that last quote seems a little odd when placed next to your
signature... :-)

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Goldberg  
View profile  
 More options Aug 9 2003, 10:48 pm
Newsgroups: perl.perl6.language
From: ben.goldb...@hotpop.com (Benjamin Goldberg)
Date: Sat, 09 Aug 2003 22:29:57 -0400
Local: Sat, Aug 9 2003 10:29 pm
Subject: Re: Perl 6's for() signature

Jonadab The Unsightly One wrote:

> John Siracusa <sirac...@mindspring.com> writes:

> > Did this ever get resolved to anyone's satisfaction?  While reading
> > EX6, I found myself wonder exactly what for() would look like in
> > Perl 6 code...

> A for loop[1] is basically syntax sugar for a while loop.  In general,
> where foo, bar, baz, and quux are expressions, the following are equivalent:

> for (foo; bar; baz) { quux }
> foo; while (bar) { quux; baz }

Well, except that in the second, any variables declared in foo will leak
into the scope after the end of the for loop.  Also, in the second,
"baz" is inside the same scope as quux, whereas in the normal C-style
for loop, it's not.

Thus, "for (foo; bar; baz) { quux }" is really more like:

   {
      foo;
      start_for_loop:
      if( !bar ) { goto end_for_loop }
      { quux }
      baz;
      goto start_for_loop;
      end_for_loop:
   };

> If Perl6 has enough syntax-sugar ability to let you turn the former
> into the latter, then you don't need to worry about for's signature.

Well, yes.  But the point of this discussion is, precisely what *kind*
of syntactic sugar will be used.

> [1]  Of course I mean a C-style for loop.

--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Aug 10 2003, 1:48 am
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: 09 Aug 2003 23:22:16 -0600
Local: Sun, Aug 10 2003 1:22 am
Subject: Re: Perl 6's for() signature

Actually, in Perl 6, they'll do that anyway.  Scope in loops is
strictly defined by the location of the braces WRT the location of
"my".  That is:

    while (my $x = somefunc()) { ... }
    # $x still in scope

And the same for all other loops.  C<for> loops are an "exception",
sortof, because they're really declaring a parameterized block instead
of a lexical variable.

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Austin Hastings  
View profile  
 More options Aug 10 2003, 9:48 am
Newsgroups: perl.perl6.language
From: Austin_Hasti...@Yahoo.com (Austin Hastings)
Date: Sun, 10 Aug 2003 08:18:27 -0500
Local: Sun, Aug 10 2003 9:18 am
Subject: RE: Perl 6's for() signature

> -----Original Message-----
> From: Luke Palmer [mailto:fibon...@babylonia.flatirons.org]
> Actually, in Perl 6, they'll do that anyway.  Scope in loops is
> strictly defined by the location of the braces WRT the location of
> "my".  That is:

>     while (my $x = somefunc()) { ... }
>     # $x still in scope

> And the same for all other loops.  C<for> loops are an "exception",
> sortof, because they're really declaring a parameterized block instead
> of a lexical variable.

It seems like we could maybe generalize this "exception":

In cases where we say

  my &block = -> $a, $b { do_stuff; }

  for (my $a = 0, $b = 1; $a < $b; ++$a) block;

We're really just pulling the block vars out so we can tweak them.

Perhaps the right approach is that all lexically scoped vars declared
"within" loop keywords that take blocks are parameters, and persist until
the end of the loop-block.

  while (my $line = <>) { # or loop, or for, or do/while, or whatever
   ...
  }

  print $line; # error -- line out of scope

The obvious accompaniment is C<is scoped(BLOCK)> or maybe C<is persistent>.

  FOR_LOOP:
  for (...) {
    while (my $line is scoped(FOR_LOOP) = <>) {
      ...
    }
    print $line; # Okay -- $line ends with the for.
  }

=Austin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Austin Hastings  
View profile  
 More options Aug 11 2003, 8:48 pm
Newsgroups: perl.perl6.language
From: Austin_Hasti...@Yahoo.com (Austin Hastings)
Date: Mon, 11 Aug 2003 19:05:33 -0500
Local: Mon, Aug 11 2003 8:05 pm
Subject: RE: Perl 6's for() signature

Which begs the question:

  my &blk = -> $a, $b {...};

  for (@list) &blk;

What happens?

(IOW, how do we map locals/parameters into block vars?)

Or, given

  my &blk = -> $a {...};

  loop (my ($x, $max) = (0, -1);
        $x < $num_elts;
        $x++, $max = max($max, $x)),
     &blk;

What happens?

(IOW, in a "target-rich" environment, how do we know what to bind?)

> Then again, C<for>
> could be made to do that using named parameters, but I don't think it
> will (there are some nasty traps with variables in outer scopes).  It's
> easy enough to say:

>     loop (my ($a, $b) = (0, 1); $a < $b; ++$a) { block($a, $b) }

Or maybe we have to say

    loop (...) -> $a &blk;

But that's nasty.

> Now on to your argument :-)

> > We're really just pulling the block vars out so we can tweak them.

> Yeah, sortof.

...

> It's a beginner trap, so Larry changed it to follow intuition.  It can
> be useful in a couple places, and it never really gets in your way.  So,
> poof, no more magic scopes.

Hooray for newbies. And that's a good point.

I'm still curious about the binding rules, though.

=Austin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonadab The Unsightly One  
View profile  
 More options Aug 13 2003, 12:48 am
Newsgroups: perl.perl6.language
From: jona...@bright.net (Jonadab The Unsightly One)
Date: 13 Aug 2003 00:07:59 -0400
Local: Wed, Aug 13 2003 12:07 am
Subject: Re: Perl 6's for() signature

Luke Palmer <fibon...@babylonia.flatirons.org> writes:
> Yes, it's possible to have two routines with the same name which
> differ by signature... however, in Perl 6, C<for> has only one
> signature, and it's the one above.  The C<for> loop you are thinking
> of is spelled C<loop>,

Oh, yes, forgot about that.

> To the contrary, C<while> and C<if> take only a single expression in
> scalar context, whereas C<for> takes a list in flattening list
> context.

*light dawns*

That's what I get for trying to start reading in the middle of a
thread, I guess.

> > Methinks that a signature should be able to call for a code block
> > in braces, and when it's called the signature after that code
> > block should be optional.

> You mean s:2nd/signature/semicolon/ ?

Yes, that was a thinko.  I thought I typed semicolon there.

> This has already been discussed at length.  The answer is "um". :-)

I see.

> So far documented, the semicolon is only optional when the closing
> brace is the only thing on the line.  Don't worry, Larry's got a
> handle on this one, and I don't think it needs further discussion.

Cool.

> >     Fooey, English is weird, let's stick with Perl.

> Hmm, that last quote seems a little odd when placed next to your
> signature... :-)

What, my little pathetic attempt at a JAPH?  It's only even slightly
hard to follow if you don't understand closures.  Nothing like some of
the clever monstrosities I've seen floating around on the net.

--
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »