perl6

Obtaining the Pod of a module without explicitly exporting it

℡╲_俬逩灬. 提交于 2019-12-01 15:58:04
问题 The documentation in Perl 6 programs, using the Pod 6 DSL, are actually parsed as part of the code; this makes that documentation available, inside the program, as the $=pod variable. However, I'd like to have access to that variable in order to process it from, say, tests. In this example I wrote for the Perl 6 Advent Calendar it's simply exported as a class (grammar, in this case) variable: our $pod = $=pod[0]; I can then use it this way: use Data::Dump; use MONKEY-SEE-NO-EVAL; sub MAIN(

Macros do not allow definition of lexical variables

烂漫一生 提交于 2019-12-01 15:54:54
问题 This code that uses (experimental) macros: use experimental :macros; macro new-var() { quasi { my $a = 42 } }; new-var; say $a Fails with Variable '$a' is not declared , although the macro passes through without an error. If that's a correct macro declaration, what does it do? If it's not, is there a way to define new variables from within a macro? 回答1: The answer from moritz is correct about the state of macros, though from what I know of the work being done in 007, I don't think the program

How should I handle Perl 6 $*ARGFILES that can't be read by lines()?

£可爱£侵袭症+ 提交于 2019-12-01 15:34:43
I'm playing around with lines which reads lines from the files you specify on the command line: for lines() { put $_ } If it can't read one of the filenames it throws X::AdHoc (one day maybe it will have better exception types so we can grab the filename with a .path method). Fine, so catch that: try { CATCH { default { put .^name } } for lines() { put $_ } } So this catches the X::AdHoc error but that's it. The try block is done at that point. It can't .resume and try the next file: try { CATCH { default { put .^name; .resume } } # Nope for lines() { put $_ } } Back in Perl 5 land you get a

Why/how is an additional variable needed in matching repeated arbitary character with capture groups?

你离开我真会死。 提交于 2019-12-01 15:27:12
I'm matching a sequence of a repeating arbitrary character, with a minimum length, using a perl6 regex. After reading through https://docs.perl6.org/language/regexes#Capture_numbers and tweaking the example given, I've come up with this code using an 'external variable': #uses an additional variable $c perl6 -e '$_="bbaaaaawer"; /((.){} :my $c=$0; ($c)**2..*)/ && print $0'; #Output: aaaaa To aid in illustrating my question only, a similar regex in perl5: #No additional variable needed perl -e ' $_="bbaaaaawer"; /((.)\2{2,})/ && print $1'; Could someone enlighten me on the need/benefit of

Perl6: variable number of arguments to function/subroutine

独自空忆成欢 提交于 2019-12-01 15:26:26
I want to be able to run a function with a variable number of parameters in Perl6, but after reading through https://docs.perl6.org/language/functions#Arguments I don't see how it can be done. I see numerous links for other languages, and a warning that "Questions with similar titles have frequently been downvoted" but I don't see this anywhere in the documentation or StackOverflow. I want to do something like this: some-test($v1, $v2) or some-test($v3) but not have a separate function using multi for each How can I construct a Perl6 subroutine which will accept a variable number of strings?

How to use :since with CompUnit

↘锁芯ラ 提交于 2019-12-01 15:20:49
问题 I am trying to create a cache of POD6 by precompiling them using the CompUnit set of classes. I can create, store and retrieve pod as follows: use v6.c; use nqp; my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO); my $precomp = CompUnit::PrecompilationRepository::Default.new(store=> $precomp-store ); my $key = nqp::sha1('test.pod6'); 'test.pod6'.IO.spurt(q:to/CONTENT/); =begin pod =TITLE More and more Some more text =end pod CONTENT $precomp.precompile('test.pod6'

How should I handle Perl 6 $*ARGFILES that can't be read by lines()?

三世轮回 提交于 2019-12-01 15:19:22
问题 I'm playing around with lines which reads lines from the files you specify on the command line: for lines() { put $_ } If it can't read one of the filenames it throws X::AdHoc (one day maybe it will have better exception types so we can grab the filename with a .path method). Fine, so catch that: try { CATCH { default { put .^name } } for lines() { put $_ } } So this catches the X::AdHoc error but that's it. The try block is done at that point. It can't .resume and try the next file: try {

Perl6: variable number of arguments to function/subroutine

邮差的信 提交于 2019-12-01 14:19:48
问题 I want to be able to run a function with a variable number of parameters in Perl6, but after reading through https://docs.perl6.org/language/functions#Arguments I don't see how it can be done. I see numerous links for other languages, and a warning that "Questions with similar titles have frequently been downvoted" but I don't see this anywhere in the documentation or StackOverflow. I want to do something like this: some-test($v1, $v2) or some-test($v3) but not have a separate function using

Can I change the Perl 6 slang inside a method?

做~自己de王妃 提交于 2019-12-01 08:06:35
A Perl 6 Regex is a more specific type of Method , so I had the idea that maybe I could do something black-magicky in a regular method that produces the same thing. I particularly am curious about doing this without changing any grammars. However, looking at Perl6/Grammar.nqp (which I barely understand), that this is really not an inheritance thing. I think, based on my reading, that the Perl 6 grammar switches slangs (sub languages) when it sees one of the regex declarators. That is, a different grammar parses the guts of regex { ... } and method {...} . So, first, is that right? Then, just

Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer)

烈酒焚心 提交于 2019-12-01 05:57:49
The following Perl 5 script: use strict; use warnings; use Data::Printer; my @a = (1,2,3,4); p @a; gives output: (note the blue color), whereas this Perl 6 scripts: use Data::Printer:from<Perl5>; my @a = 1,2,3,4; p @a; gives output: [ [0] 1, [1] 2, [2] 3, [3] 4 ] but the numbers are not colored (as for the Perl 5 case above). System information : $ perl --version This is perl 5, version 29, subversion 3 (v5.29.3) built for x86_64-linux $ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler.version' ubuntu (18.10.Cosmic.Cuttlefish) moar (2018.11) v2018.11 This seems to be an issue with version 0