On Wed Jul 14 21:43:09 2010, supernovus wrote:
> Say you have a module file called Greetings.pm6 that contains:
> 
> use v6;
> module Greetings {
>   sub hello($name='World') {
>     say "Hello $name";
>   }
> }
> 
> If you were to do: perl6 -e 'use Greetings; hello("moon");'
> It would appropriately print "Hello moon";
> 
> If you were to go into the REPL, you will find some more mysterious
> behavior:
> 
> > use Greetings; hello('Moon');
> Hello Moon
> > hello()
> Could not find sub &hello
> 
> A new session:
> 
> > use Greetings;
> > hello()
> Could not find sub &hello
> > use Greetings;
> P
> > hello()
> Hello World
> 
> It seems that any module that exports a subroutine, does not have the
> subroutine exported in the REPL unless you call the 'use' statement 
twice.
> 
> You can test this with a module included with Rakudo:
> 
> > use DateTime::strftime;
> > strftime('%A', DateTime.now)
> Could not find sub &strftime
> > use DateTime::strftime;
> P
> > strftime('%A', DateTime.now)
> Thursday
> 
> I am assuming this behavior is a bug and is not expected.

If you update the original sample to export the sub (it won't work in 
either case now without that):

$ cat Greetings.pm
use v6;
module Greetings {
  sub hello($name='World') is export {
    say "Hello $name";
  }
}

Both cases work fine with a recent rakudo:

$ ./perl6  -e 'use Greetings; hello("moon")'
Hello moon
$ ./perl6
> use Greetings;
Nil
> hello("moon");
Hello moon
> 

This ticket is closable with tests.



-- 
Will "Coke" Coleda

Reply via email to