小编p6s*_*eve的帖子

我在哪里可以了解perl6类型变量(:: T)

我需要使用perl6类型的变量.似乎最终的手册是http://www.jnthn.net/papers/2008-yapc-eu-perl6types.pdf,它简洁而且有用.

我能指出哪些更全面或更权威的东西?

perl6

6
推荐指数
2
解决办法
135
查看次数

Perl6 Regex Match Num

我想从文本字符串的一部分匹配任何Num.到目前为止,这个(从https://docs.perl6.org/language/regexes.html#Best_practices_and_gotchas中窃取)完成了这项工作......

    my token sign { <[+-]> }
    my token decimal { \d+ }
    my token exponent { 'e' <sign>? <decimal> }
    my regex float {
        <sign>?
        <decimal>?
        '.' 
        <decimal>
        <exponent>?
    }   
    my regex int {
        <sign>?
        <decimal>
    }   
    my regex num {
        <float>?
        <int>?
    }   
    $str ~~ s/( <num>? \s*) ( .* )/$1/;
Run Code Online (Sandbox Code Playgroud)

这似乎很多(容易出错)重新发明轮子.是否有perl6技巧可以在语法中匹配内置类型(Num,Real等)?

perl6

5
推荐指数
1
解决办法
127
查看次数

一个perl6模块可以有条件地"使用"另一个perl6模块吗?

是否有一种合理的方法让一个perl6模块检查是否存在另一个perl6模块,并且当且仅当它被安装时才"使用"它?

像这样......

module Polygons;

if $available {
    use Measure;                #only if Measure is installed
}

class Rectangle is export {
    has $.width;
    has $.height;

    method area {
        $!width * $!height;     #provides operator overload for Measure * Measure
    }
}
#====================

module Measure;

class Measure is export {
    has $.value;
    has $.unit;

    method Real {
        $!value;
    }
    method Str {
        "$!value $!unit";
    }
    method multiply( $argument ) {
        my $result = $.;
        $result.value = $!value * $argument;
        $result.unit  = "$!unit2";
        return …
Run Code Online (Sandbox Code Playgroud)

perl6

5
推荐指数
1
解决办法
129
查看次数

(如何) raku 做类同义词?

我有

class Length is Measure export { ... }
Run Code Online (Sandbox Code Playgroud)

我想要的同义词仅在于类名不同,我试过这个:

class Distance   is Length is export {}
class Breadth    is Length is export {}
class Width      is Length is export {}
class Height     is Length is export {}
class Depth      is Length is export {}
Run Code Online (Sandbox Code Playgroud)

这种在 $distance ~~ Length 中有效,但我也想要 $length ~~ Distance。

某些类型或强制将是可取的 - 例如 $length.Distance ~~ Distance 阻止像 $width = $height + $depth 这样的操作(即你不能总是添加指向不同轴的长度)。

也许某种类 := 名称绑定,或者强制 NxN 的速记方式?

非常感谢收到任何建议......

oop raku

5
推荐指数
1
解决办法
98
查看次数

在子模块中重用父符号

我正在寻求在子模块中重复使用与其父模块中相同的角色/类名称。你知道,就像一个专业。

\n

use Dan目的是通过简单地更改为use Dan::Pandas顶部,能够为父系列和子系列变体重复使用相同的脚本代码。

\n

我试图坚持角色而不是类组成,以便可以将行为应用于其他对象,例如。class GasBill does Series;

\n

这是 MRE:

\n
me@ubuntu:~/spike# tree\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lib\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Dan\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Pandas.rakumod\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dan.rakumod\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 spike.raku\n
Run Code Online (Sandbox Code Playgroud)\n

丹·拉库莫德:

\n
  1 unit module Dan;\n  2 \n  3 role Series is export {\n  4     method no { "no" }\n  5 }\n
Run Code Online (Sandbox Code Playgroud)\n

熊猫.rakumod:

\n
  1 unit module Dan::Pandas;\n  2 \n  3 use Dan;\n  4 \n  5 role Series does Dan::Series is export {\n  6     method yo { "yo" }\n …
Run Code Online (Sandbox Code Playgroud)

oop raku

5
推荐指数
2
解决办法
126
查看次数

是否有可能将某个值提升到 Grammar TOP?

我有这个 raku 语法:

#!/usr/bin/env raku
use v6.d;

use Grammar::Tracer;

grammar Grammar {
    token TOP {
          <city>      \v
          <state-zip> \v?
    }
    token city {
        ^^ \V* $$
    }
    token state-zip {
        ^^ <state> <.ws>? <zipcode> $$    #<.ws> is [\h* | \v]
    }
    token state {
        \w \w
    }
    token zipcode {
        \d ** 5
    }
}

class Actions {
    method TOP($/) {
        #works
        say "city is ",    $_ with $<city>.made;
        say "state is ",   $_ with $<state-zip><state>.made;
        say "zipcode is ", …
Run Code Online (Sandbox Code Playgroud)

grammar parsing raku

5
推荐指数
1
解决办法
136
查看次数

可以将TT2与Cro一起使用吗?

我正在考虑使用perl6和Cro来构建一个包含文本内容的网站.是否有关于使用模板工具包(如TT2)和代码示例使用Cro的最佳实践/指导?

template-toolkit perl6 cro

4
推荐指数
1
解决办法
177
查看次数

标签 统计

perl6 ×4

raku ×3

oop ×2

cro ×1

grammar ×1

parsing ×1

template-toolkit ×1