标签: perl6

Perl 5和Perl 6中的Unicode属性"Space"

unicode属性\p{Space}是Perl5扩展吗?

Perl5 Space匹配所有白色空格

my $s = "one\ttwo\nthree";
$s =~ s/\p{Space}/*/g;
say $s;

# one*two*three
Run Code Online (Sandbox Code Playgroud)

而在Per6中它可能只匹配一个简单的空间

my $s = "one\ttwo\nthree";
$s.=subst( /<:Space>/, '*', :g );
say $s;

# one     two
# three
Run Code Online (Sandbox Code Playgroud)

unicode perl whitespace perl6

3
推荐指数
1
解决办法
118
查看次数

Perl6:如何在用户定义的字符类或范围中使用<alpha>?

我试图匹配任何字母字符和","或";" 我试图根据文档https://docs.perl6.org/language/regexes使用"<:L>字母字符" .但是,编译器抱怨.不使用a..zA..Z这样做的正确方法是什么?

say "a,b,c;d,e;xyz" ~~ m/ <[ <alpha> \, \; ]>+ /;
Run Code Online (Sandbox Code Playgroud)

错误信息:

Potential difficulties:
    Repeated character (a) unexpectedly found in character class
    at C:\Users\Guest\Documents/avg.pl:128
    ------> ay "a,b,c;d,e;xyz" ~~ m/ <[ <alpha> \, \<HERE>; ]>+ /;
Run Code Online (Sandbox Code Playgroud)

非常感谢你 !!

regex range match perl6

3
推荐指数
1
解决办法
169
查看次数

导入简单模块

我有一个在模块文件(.pm)中编写的函数,并希望在Perl6文件(.pl6)中使用它.这两个文件位于同一个文件夹中:

C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\perlCode
Run Code Online (Sandbox Code Playgroud)

我试图使用Perl6的答案:隐式和显式导入但我的代码返回了这个错误:

===SORRY!=== Could not find chrmodule1 at line 5 in:
    C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\modules
    C:\Users\Christian\.perl6
    C:\rakudo\share\perl6\site
    C:\rakudo\share\perl6\vendor
    C:\rakudo\share\perl6
    CompUnit::Repository::AbsolutePath<84241584>
    CompUnit::Repository::NQP<86530680>
    CompUnit::Repository::Perl5<86530720> [Finished in 0.436s]
Run Code Online (Sandbox Code Playgroud)

这是.pm文件,chrmodule1.pm:

module chrmodule1 {
    sub foo is export(:DEFAULT, :one) {
        say 'in foo';
    }
}
Run Code Online (Sandbox Code Playgroud)

这是.pl6文件,testOfCode3.pl6:

use v6;
use lib 'modules';
use chrmodule1;

foo();
Run Code Online (Sandbox Code Playgroud)

module perl6

3
推荐指数
1
解决办法
207
查看次数

Int的数组与Int的数组的数组

我想要一个多子,其中一个用于Ints数组,另一个多子用于Ints数组.

这似乎可以解决问题:

multi sub abc(Int @array) { say 10; }

multi sub abc(Array[Int] @array) { say 20; }
Run Code Online (Sandbox Code Playgroud)

但是,构建满足这些约束的文字是非常冗长的:

abc Array[Int].new([1,2,3]);   # -> 10

abc Array[Array[Int]].new([Array[Int].new([1,2,3]), Array[Int].new([2,3,4])]);   # -> 20
Run Code Online (Sandbox Code Playgroud)

理想情况下,我只能说:

abc [1,2,3]
abc [[1,2,3], [2,3,4]]
Run Code Online (Sandbox Code Playgroud)

有没有办法构建一个abc如上所示可以调度而没有所有显式类型注释的方法?

可以multi sub设置为在运行时调度吗?

perl6

3
推荐指数
1
解决办法
107
查看次数

在Perl 6中的代码点上拆分

如何在字母集群上拆分代码点?

样品:

"???????".comb()
--> output (?? ?? ? ??)
Run Code Online (Sandbox Code Playgroud)

我如何得到以下内容?

 (? ? ? ? ? ? ?)
Run Code Online (Sandbox Code Playgroud)

perl6

3
推荐指数
1
解决办法
152
查看次数

Perl6解析文件

作为练习,我试图解析一些标准文本,它是shell命令的输出.

  pool: thisPool
 state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
    still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
    the pool may no longer be accessible by software that does not support
    the features. See zpool-features(5) for details.
  scan: none requested
config:

    NAME                                                STATE     READ WRITE CKSUM
    homePool                                            ONLINE       0     0     0
      mirror-0                                          ONLINE       0     0     0
        ata-WDC_WD5000AZLX-00CL5A0_WD-WCC3F7NUE93C      ONLINE       0     0     0 …
Run Code Online (Sandbox Code Playgroud)

regex grammar perl6

3
推荐指数
1
解决办法
182
查看次数

从Perl 6中的数组值的哈希中检索数据

我有一个包含3个元素的数组:

my @a = <x y z>;
Run Code Online (Sandbox Code Playgroud)

然后我用Array值创建一个哈希,并使其@a内容成为其值之一:

my Array %h;
%h<a> = @a;
Run Code Online (Sandbox Code Playgroud)

稍后我检索此值并将其分配给另一个数组:

my @A = %h<a>;
Run Code Online (Sandbox Code Playgroud)

但我得到的@A不是一个包含3个元素的数组,而是一个元素的数组,它本身就是一个包含3个元素的数组:

say @A;          # [[x y z]]
say @A[0].elems; # 3
Run Code Online (Sandbox Code Playgroud)

所以,%h<a>push编入@A.

我的代码中的错误在哪里?

UPD:这似乎解决了这个问题,但并没有提高我的理解力.:)

my @A = @(%h<a>);
say @A; [x y z]
Run Code Online (Sandbox Code Playgroud)

perl6

3
推荐指数
1
解决办法
134
查看次数

无法使用Rakudo Perl 6 zef安装Readline

我正在尝试安装Readline.

(该系统是Linux Mint Mate 18.3,Lubuntu 17.10也是如此).

$ zef install Readline
Run Code Online (Sandbox Code Playgroud)

安装过程开始,但稍后将中止以下消息:

===> Searching for: Readline
===> Searching for missing dependencies: LibraryCheck
===> Testing: LibraryCheck:ver<0.0.6>:auth<github:jonathanstowe>
===> Testing [OK] for LibraryCheck:ver<0.0.6>:auth<github:jonathanstowe>
===> Testing: Readline:ver<0.0.2>:auth<github:drforr>
# Failed test 'initialize'
# at t/02-base.t line 10
# Cannot locate native library 'libreadline.so': libreadline.so: cannot open shared object file: No such file or directory
    # Failed test 'macro-dumper lives'
    # at t/02-base.t line 18
    # Cannot locate native library 'libreadline.so': libreadline.so: cannot open shared object file: …
Run Code Online (Sandbox Code Playgroud)

rakudo perl6 rakudo-star zef

3
推荐指数
1
解决办法
490
查看次数

约束multis及其用于选择它们

约束显然不用于选择一个 multi

multi sub cuenta( Str $str ) { say $str };
multi sub cuenta( $file where .IO.e ) { say $file.IO.slurp };
cuenta( $*PROGRAM-NAME ); # Outputs the file name
Run Code Online (Sandbox Code Playgroud)

这意味着它使用的是第一个,而不是第二个.但是,这可以按预期工作:

subset real-files of Str where .IO.e;
multi sub cuenta( Str $str ) { say $str };
multi sub cuenta( real-files $file ) { say $file.IO.slurp };
cuenta( $*PROGRAM-NAME );
Run Code Online (Sandbox Code Playgroud)

打印程序本身的内容.这可能说明了类型检查和多调度,但我不确定它是设计还是只是一个怪癖.任何的想法?

perl6 dispatch

3
推荐指数
1
解决办法
59
查看次数

使用NativeCall将C库函数合并到Perl6中

我试图在Perl6中使用lgammaC语言math.h.

我如何将其融入Perl6?

我试过了

use NativeCall;

sub lgamma(num64 --> num64) is native(Str) {};

say lgamma(3e0);

my $x = 3.14;
say lgamma($x);
Run Code Online (Sandbox Code Playgroud)

这适用于第一个数字(a Str)但第二个数字失败$x,给出错误:

This type cannot unbox to a native number: P6opaque, Rat
  in block <unit> at pvalue.p6 line 8
Run Code Online (Sandbox Code Playgroud)

我想这样做非常简单,就像在Perl5中那样:use POSIX 'lgamma';然后lgamma($x)我不知道如何在Perl6中做到这一点.

perl6 nativecall

3
推荐指数
2
解决办法
186
查看次数

标签 统计

perl6 ×10

regex ×2

dispatch ×1

grammar ×1

match ×1

module ×1

nativecall ×1

perl ×1

rakudo ×1

rakudo-star ×1

range ×1

unicode ×1

whitespace ×1

zef ×1