Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is namespace qualification really required

5 views
Skip to first unread message

phil...@sunflower.com

unread,
Jul 15, 2005, 3:16:48 PM7/15/05
to perl6-c...@perl.org
I've been playing with pugs a little bit. I like it a lot. I'm especially interested in passing parameters to subs and giving them defaults.

While trying to Curry in the default of a Code reference parameter, I ran into the following oddity (it seems odd to me). It looks like I must fully qualify the package name in order to specify a default sub. Here's a reduced example:

package MyModule;

use v6;

sub doubler( Num $x ) {
return 2 * $x;
}

sub value_v( Code +$func = &MyModule::doubler ) is export {
return $func( 5 );
}

This works. But I think I should be able to say:

sub value_v( Code +$func = doubler ) is export {

or at least:

sub value_v( Code +$func = &doubler ) is export {

I'm using Pugs 6.2.8. Am I missing something?

Phil Crow

Autrijus Tang

unread,
Jul 16, 2005, 12:01:11 AM7/16/05
to phil...@sunflower.com, perl6-c...@perl.org
On Fri, Jul 15, 2005 at 02:16:48PM -0500, phil...@sunflower.com wrote:
> package MyModule;
>
> use v6;
> sub doubler( Num $x ) {
> return 2 * $x;
> }
>
> sub value_v( Code +$func = &MyModule::doubler ) is export {
> return $func( 5 );
> }
>
> This works. But I think I should be able to say:
>
> sub value_v( Code +$func = doubler ) is export {

That won't do, as it will call the doubler.

> sub value_v( Code +$func = &doubler ) is export {

This should work; if it does not, it is a bug. Can you add a
regression test as, say, t/subroutines/defaults.t? I have just
sent you a committer invitation.

Thanks!
/Autrijus/

Autrijus Tang

unread,
Jul 18, 2005, 10:47:48 AM7/18/05
to phil...@sunflower.com, Autrijus Tang, perl6-c...@perl.org
On Mon, Jul 18, 2005 at 09:00:50AM -0500, phil...@sunflower.com wrote:
> I made the test. The problem only occurs when the sub is called from
> another package, in my case that was a driving script.
>
> I'm not sure how to accept the invitation (or what that even means).

Oh. It means you should have received a mail from openfoundry.org
that contains a URL to be registered on http://rt.openfoundry.org/ --
the system that manages Pugs committership. You can also go to that
website and register manually, using your mail address; once you
have done so, you'll be listed among Pugs committers, and then
you can commit in your test using the username/password chosen at
the registration time.

If you are using command-line svn, the sequence should be:

svn co http://svn.openfoundry.org/pugs
cd pugs
# ... create t/subroutines/defaults.t ...
# ... edit AUTHORS to add your name ...
svn add t/subroutines/defaults.t
svn ci

If you are using svk, the sequence is exactly the same, with the
"svn" replaced with "svk".

Thanks,
/Autrijus/

phil...@sunflower.com

unread,
Jul 18, 2005, 10:00:50 AM7/18/05
to Autrijus Tang, perl6-c...@perl.org
> Autrijus Tang <autr...@autrijus.org> wrote:
>
> On Fri, Jul 15, 2005 at 02:16:48PM -0500, phil...@sunflower.com wrote:
> > package MyModule;
> > > use v6;
> > sub doubler( Num $x ) {
> > return 2 * $x;
> > }
> > > sub value_v( Code +$func = &MyModule::doubler ) is export {
> > return $func( 5 );
> > }
> > > This works. But I think I should be able to say:
> > > sub value_v( Code +$func = doubler ) is export {
>
> That won't do, as it will call the doubler.

That makes sense.


>
> > sub value_v( Code +$func = &doubler ) is export {
>
> This should work; if it does not, it is a bug. Can you add a
> regression test as, say, t/subroutines/defaults.t? I have just
> sent you a committer invitation.
>

I made the test. The problem only occurs when the sub is called from another package, in my case that was a driving script.

I'm not sure how to accept the invitation (or what that even means). Sorry, I'm new here.

Phil

phil...@sunflower.com

unread,
Jul 18, 2005, 3:47:06 PM7/18/05
to Autrijus Tang, perl6-c...@perl.org
> Autrijus Tang <autr...@autrijus.org> wrote:
>
> On Mon, Jul 18, 2005 at 09:00:50AM -0500, phil...@sunflower.com wrote:
> > I made the test. The problem only occurs when the sub is called from
> > another package, in my case that was a driving script.
> > > I'm not sure how to accept the invitation (or what that even means).
>
> Oh. It means you should have received a mail from openfoundry.org
> that contains a URL to be registered on http://rt.openfoundry.org/ --

I see.


>
> If you are using command-line svn, the sequence should be:
>
> svn co http://svn.openfoundry.org/pugs
> cd pugs
> # ... create t/subroutines/defaults.t ...
> # ... edit AUTHORS to add your name ...
> svn add t/subroutines/defaults.t
> svn ci

I did this. I included two tests, one without multiple packages (which works) and one with them (which fails). I marked the second test todo.

Thanks for the gentle help with this process.

If there is any chance I could fix this problem, I'd try. But, I would need some pointers.

Phil

Autrijus Tang

unread,
Jul 19, 2005, 11:01:41 AM7/19/05
to phil...@sunflower.com, Autrijus Tang, perl6-c...@perl.org
On Mon, Jul 18, 2005 at 02:47:06PM -0500, phil...@sunflower.com wrote:
> I did this. I included two tests, one without multiple packages (which
> works) and one with them (which fails). I marked the second test todo.

...and I fixed the bug promptly. :)

> Thanks for the gentle help with this process.

No problem. Welcome aboard!

Thanks,
/Autrijus/

phil...@sunflower.com

unread,
Jul 19, 2005, 1:53:19 PM7/19/05
to Autrijus Tang, perl6-c...@perl.org
> Autrijus Tang <autr...@autrijus.org> wrote:
>
> On Mon, Jul 18, 2005 at 02:47:06PM -0500, phil...@sunflower.com wrote:
> > I did this. I included two tests, one without multiple packages (which
> > works) and one with them (which fails). I marked the second test todo.
>
> ...and I fixed the bug promptly. :)

Thanks for working on this, but there is still a problem.

When I run make test, the two tests both pass. When I run the test as:

perl -Iblib/lib t/subroutines/defaults.t

I get errors:
1..2
ok 1 - default sub called
not ok 2 - default sub called in package namespace
# Failed test (t/subroutines/defaults.t line 35, column 1-62)
# Got: undef
# Looks like you failed 1 tests of 2

Further, the original example still fails. This is all quite confusing to me. When I saw the tests pass during make test, I thought I was set to move on to my real example. Now I don't know which way is up.

Phil

Autrijus Tang

unread,
Jul 19, 2005, 2:03:46 PM7/19/05
to phil...@sunflower.com, Autrijus Tang, perl6-c...@perl.org
On Tue, Jul 19, 2005 at 12:53:19PM -0500, phil...@sunflower.com wrote:
> Thanks for working on this, but there is still a problem.
>
> When I run make test, the two tests both pass. When I run the test as:
>
> perl -Iblib/lib t/subroutines/defaults.t

"perl"?

> I get errors:
> 1..2
> ok 1 - default sub called
> not ok 2 - default sub called in package namespace
> # Failed test (t/subroutines/defaults.t line 35, column 1-62)
> # Got: undef
> # Looks like you failed 1 tests of 2

Did you perhaps had an order version of pugs in PATH?

> Further, the original example still fails. This is all quite confusing to
> me. When I saw the tests pass during make test, I thought I was set to
> move on to my real example. Now I don't know which way is up.

Hm, put your real example to the test file, then?

Thanks,
/Autrijus/

Flavio S. Glock

unread,
Jul 19, 2005, 2:24:57 PM7/19/05
to perl6-c...@perl.org
I was trying to debug this problem in Prelude.pm - I think it is the same bug:

pugs> my $x=1.222
1.222
pugs> $x.round
*** Undeclared variable: "&do_round"
at src/perl6/Prelude.pm line 278, column 9 - line 279, column 5

- Flavio S. Glock

phil...@sunflower.com

unread,
Jul 19, 2005, 2:58:18 PM7/19/05
to Autrijus Tang, perl6-c...@perl.org
> Autrijus Tang <autr...@autrijus.org> wrote:
>
>
> > I get errors:
> > 1..2
> > ok 1 - default sub called
> > not ok 2 - default sub called in package namespace
> > # Failed test (t/subroutines/defaults.t line 35, column 1-62)
> > # Got: undef
> > # Looks like you failed 1 tests of 2
>
> Did you perhaps had an order version of pugs in PATH?

Ouch. Yes, of course. All is well. Thanks.

Now I want to contribute an example. It shows off named parameters with default values (including those of code type :-) as well as currying. It does this by implementing Newton's method for root finding. Is this appropriate for inclusion in the examples directory? If so, where should it go in that directory?

Phil

Autrijus Tang

unread,
Jul 19, 2005, 3:03:38 PM7/19/05
to phil...@sunflower.com, Autrijus Tang, perl6-c...@perl.org
On Tue, Jul 19, 2005 at 01:58:18PM -0500, phil...@sunflower.com wrote:
> Now I want to contribute an example. It shows off named parameters with
> default values (including those of code type :-) as well as currying. It
> does this by implementing Newton's method for root finding. Is this
> appropriate for inclusion in the examples directory? If so, where should
> it go in that directory?

examples/algorithms/ most likely.

Thanks,
/Autrijus/

Flavio S. Glock

unread,
Jul 20, 2005, 4:26:50 PM7/20/05
to perl6-c...@perl.org
Autrijus Tang said:
> ...and I fixed the bug promptly. :)

I'm getting this error:

pugs> 10.round


*** Undeclared variable: "&do_round"
at src/perl6/Prelude.pm line 278, column 9 - line 279, column 5

This is the Prelude code:

sub do_round($n) is primitive is safe {
($n < 0) ?? int( $n - 0.5) :: int($n + 0.5);
}
sub round($n) is primitive is safe {
round_gen($n, &do_round)
}

I'm using r5716 in a chroot I just created, so I'm sure there are no
older versions around.

- Flavio S. Glock

0 new messages