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
&?SUB and pointy subroutines
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
  4 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
 
Garrett Rooney  
View profile  
 More options Mar 4 2005, 8:19 pm
Newsgroups: perl.perl6.compiler
From: roo...@electricjellyfish.net (Garrett Rooney)
Date: Fri, 04 Mar 2005 20:19:07 -0500
Local: Fri, Mar 4 2005 8:19 pm
Subject: [pugs] &?SUB and pointy subroutines
I'm having some trouble using the &?SUB variable in a subroutine
declared with the -> operator.  The following code results in an error
about &?SUB being undefined:

my $s = -> $count {
   if $count < 10 {
     say $count;
     &?SUB($count + 1);
   }

};

$s(1);

If I change to either a named sub (sub foo($count) { ... }), or an
anonymous sub declared with the sub keyword (my $s = sub ($count) { ...

} ) then it works fine, it's only with the -> that it doesn't work.

Is there something wrong with my code, or is this an actual bug?

-garrett


 
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.
Garrett Rooney  
View profile  
 More options Mar 4 2005, 8:37 pm
Newsgroups: perl.perl6.compiler
From: roo...@electricjellyfish.net (Garrett Rooney)
Date: Fri, 04 Mar 2005 20:37:47 -0500
Local: Fri, Mar 4 2005 8:37 pm
Subject: Re: [pugs] &?SUB and pointy subroutines

Luke Palmer wrote:
> That's because a pointy sub is not a sub.  Perhaps we should call it a
> pointy block.

That might be clearer ;-)

> Not all code objects are Subs.  If you call "return", then you return
> from the innermost enclosing "sub", which is marked by that word.
> Likewise does $?SUB.  I don't believe $?BLOCK has been implemented yet,
> but it will.

If that's the case then the "Pointy subs" section of S06.pod should
probably be clarified a bit.  It says that -> is a synonym for an
anonymous C<sub>, except for the lack of parens around the parameter
list, lack of a need for a preceeding comma when included in a list, and
the fact that it cannot be given traits.  If there are more differences
they should probably be mentioned.

> To really illustrate the point, try this program:

>     sub foo ($ct) {
>         say "foo";
>         my $s = -> $count {
>             if $count < 10 {
>                 say $count;
>                 &?SUB($count + 1);
>             }
>         };
>         $s($ct);
>     }
>     foo(1);

Ok, I see how it works now, but I still think the docs should be
clarified a bit.

-garrett


 
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 Mar 4 2005, 8:46 pm
Newsgroups: perl.perl6.compiler
From: l...@luqui.org (Luke Palmer)
Date: Fri, 4 Mar 2005 18:46:56 -0700
Local: Fri, Mar 4 2005 8:46 pm
Subject: Re: [pugs] &?SUB and pointy subroutines

Garrett Rooney writes:
> >Not all code objects are Subs.  If you call "return", then you return
> >from the innermost enclosing "sub", which is marked by that word.
> >Likewise does $?SUB.  I don't believe $?BLOCK has been implemented yet,
> >but it will.

> If that's the case then the "Pointy subs" section of S06.pod should
> probably be clarified a bit.  It says that -> is a synonym for an
> anonymous C<sub>, except for the lack of parens around the parameter
> list, lack of a need for a preceeding comma when included in a list, and
> the fact that it cannot be given traits.  If there are more differences
> they should probably be mentioned.

Okay, it is now mentioned (I think dev.perl.org is synched nightly).

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.
Luke Palmer  
View profile  
 More options Mar 4 2005, 8:32 pm
Newsgroups: perl.perl6.compiler
From: l...@luqui.org (Luke Palmer)
Date: Fri, 4 Mar 2005 18:32:50 -0700
Local: Fri, Mar 4 2005 8:32 pm
Subject: Re: [pugs] &?SUB and pointy subroutines

That's because a pointy sub is not a sub.  Perhaps we should call it a
pointy block.

Not all code objects are Subs.  If you call "return", then you return
from the innermost enclosing "sub", which is marked by that word.
Likewise does $?SUB.  I don't believe $?BLOCK has been implemented yet,
but it will.

To really illustrate the point, try this program:

    sub foo ($ct) {
        say "foo";
        my $s = -> $count {
            if $count < 10 {
                say $count;
                &?SUB($count + 1);
            }
        };
        $s($ct);
    }
    foo(1);

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.
End of messages
« Back to Discussions « Newer topic     Older topic »