Re: Example module and its use
On Mar 28, 2015 6:23 AM, Paul Cochrane p...@liekut.de wrote: BTW: please don't use the shortcut 'v6;': AFAIU it's been deprecated in favour of 'use v6;' Hope this helps a bit. It does, thanks! BTW, I think my fumbling in learning Perl 6 is giving me some ideas for the Coookbook, at least for p6 newbies. I am keeping track of my questions and resullting simple cases to show exactly how to do something with working code--not too advanced but definitely helpful I think. In that vein, the synopses could do a better job of showing real code--maybe that's part of the cookbook I haven't seen yet. Cheers! -Tom
Re: Example module and its use
Hi Tom, use Bar :DEFAULT; but this does not: use Bar foo; So is S11 in error!! That might not necessarily be the case (however S11 certainly isn't clear about exactly how to import selected routines while `use`-ing a module). All subs/methods that are marked with `is export` are exported by default, thus there's actually no need to import anything, hence: use Bar; will ensure that the foo() routine is available within the scope of the `doit.pl` script. From what I can gather from S11, is that if one wants to override the default behaviour of importing into the current namespace everything which is exported by the module, then an EXPORT sub needs to be defined. AFAICT this is what the error: no EXPORT sub, but you provided positional argument in the 'use' statement is trying to tell you. Nevertheless, I've not been able to work out how to create an EXPORT sub which does the Right Thing(TM). Reading 'Perl6/Grammar.nqp' in the Rakudo sources shows that a sub by the name of `EXPORT` is expected which returns an `EnumMap`, which I suspect contains the names of the subs/methods to be exported. I'm fairly sure this is getting much too low-level for the current use-case. Also, sharing this information might simply be muddying the waters somewhat, so in order that you can get further with what you're trying to do, your example will work with the following code: == Bar.pm == module Bar; use v6; sub foo($a, $b, $c) is export {} # vim: expandtab shiftwidth=4 ft=perl6 = doit.pl == use v6; use lib .; use Bar; my @t = foo(1, 2, 3); # vim: expandtab shiftwidth=4 ft=perl6 BTW: please don't use the shortcut 'v6;': AFAIU it's been deprecated in favour of 'use v6;' Hope this helps a bit. Cheers, Paul
Re: Example module and its use
Hi Tom, If you put the attribute is export on a sub, then it is part of the :DEFAULT and :ALL tagsets. That means you can import them by: use Bar :DEFAULT; http://design.perl6.org/S11.html#Dynamic_exportation states: The default EXPORTALL handles symbol exports by removing recognized export items and tagsets from the argument list, *then calls the **EXPORT subroutine in that package (if there is one), passing in the remaining arguments.* The bold text is my emphasis. It seems to imply that in perl6 you can only import by tagsets without implementing an EXPORT subroutine. This strikes me as weird because of this example in S11: use Sense common @horse; but I couldn't find any examples in the spec tests. Am I missing something? -Nate On Fri, Mar 27, 2015 at 6:37 PM, Tom Browder tom.brow...@gmail.com wrote: I'm trying to get the basic syntax down on creating and using a module. I've tried this and get an error: # file 1: Bar.pm module Bar; sub foo($a, $b, $c) is export {} # file 2: doit.pl v6; use lib .; use Bar foo; my @t = foo(1, 2, 3); # in a shell $ perl6 doit.pl ===SORRY!=== Error while importing from 'Bar': no EXPORT sub, but you provided positional argument in the 'use' statement I've tried to digest the S11 synopsis on compilation units and I don't see any obvious problem. Ideas, please. Thanks. Best regards, -Tom