小编p6s*_*eve的帖子

Perl6 - 在一些子例程签名中的$:for

我在另一个问题中遇到了这个错误信息,我想知道$:部分签名的含义是什么?

Cannot resolve caller index(Str: Str, Any); none of these signatures match:
      (Str:D $: Cool:D $needle, *%_)
      (Str:D $: Str:D $needle, *%_)
      (Str:D $: Cool:D $needle, Cool:D $pos, *%_)
      (Str:D $: Str:D $needle, Int:D $pos, *%_)
Run Code Online (Sandbox Code Playgroud)

signature perl6

8
推荐指数
1
解决办法
183
查看次数

为什么perl6 multi默认为sub?

在参考这个问题/答案时,perl6 multi默认为sub.

对于<class>类型的调用者,没有这样的方法<name>

我原以为它默认为方法.有人可以解释一下这个理由吗?

perl6 dispatch

8
推荐指数
2
解决办法
133
查看次数

可以Perl6 cmp两个字符串不敏感吗?

我正在进行排序,并希望控制alpha值的cmp不区分大小写(即https://perl6.org/archive/rfc/143.html).

是否有一些:我也许是这个副词?

perl6 raku

8
推荐指数
4
解决办法
175
查看次数

有没有办法(隐式)删除 Raku 角色 mixin?

这个新问题是我之前提出的问题的后续问题,是在我充实内容时出现的。请注意,我也做了一些研究,并且有意识地避开了这里提到的 Scalar Mixins bug 。因此,我将角色混合到对象中,而不是标量容器中。

大局是进行数学运算,同时也执行简单的误差计算。

这是我的失败代码的简洁版本:

  1 role Error {       
  2     has $.abs-error 
  3 }   
  4 
  5 multi prefix:<-> ( Error:D $x ) is default {
  6     # - $x;                             # fails - enters an infinite loop 
  7     # - $x.Real;                        # fails - does not drop the Error mixin
  8     ( 0 - $x ) does Error($x.abs-error) # works - but relies on the infix:<-> form
  9 }
 10 
 11 my $dog = 12.5 does …
Run Code Online (Sandbox Code Playgroud)

units-of-measurement mixins raku

8
推荐指数
1
解决办法
116
查看次数

Raku 对中缀的模糊调用(Hyper:Dan::Series,Int)

我正在编写一个模型系列类(有点像 pandas 中的类) - 它应该是位置和关联的。

class Series does Positional does Iterable does Associative {
    has Array $.data is required;
    has Array $.index;

    ### Construction ###

    method TWEAK {
        # sort out data-index dependencies
        $!index = gather {
            my $i = 0;
            for |$!data -> $d {
                take ( $!index[$i++] => $d )
            }
        }.Array
    }

    ### Output ### 

    method Str {
        $!index
    }   

    ### Role Support ### 

    # Positional role support
    # viz. https://docs.raku.org/type/Positional

    method of {
        Mu  
    }   
    method …
Run Code Online (Sandbox Code Playgroud)

raku

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

如果通过map分配,为什么还需要触摸Hash?

当我这样做时,它起作用了(这些是方法 TWEAK 结束之前的最后 4 行。但是,我的第一次尝试没有第 3 行,并且失败了,因为 %!columns 为空...

    constant @alphi = 'A'..Inf;

    1 if ! %!columns {
    2     @alphi[0..^@!data.first.elems].map( {%!columns{$_} = $++} );
    3     %!columns  #<== have to "touch" %!columns to avoid empty hash
    4 }  
Run Code Online (Sandbox Code Playgroud)

我很高兴这个问题是通过“触摸”属性来解决的......但看起来很神奇......任何人都可以解释为什么吗?

raku

8
推荐指数
1
解决办法
71
查看次数

获取被调用者中名为 str 的方法

我想从被调用方反思方法调用的尾部。

现在我正在明确地这样做......

# caller side
s.pd: '.shape';
s.pd: '.to_json("test.json")';
s.pd: '.iloc[2] = 23';

# callee side
method pd( Str $call ) {
    given $call {
        when /shape/   { ... }
        when /to_json/ { ... }
        #etc
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我想通过“俚语方法调用”来做到这一点,就像这样编写代码......

# caller side
s.pd.shape;
s.pd.to_json("test.json");
s.pd.iloc[2] = 23;
^ ^^ ^^^^^^^^^^^^^^^^^^^$
|  |       |
|  |       L a q// str I can put into eg. a custom Grammar
|  |
|  L general method name
|
L invocant

#callee …
Run Code Online (Sandbox Code Playgroud)

oop raku

8
推荐指数
1
解决办法
55
查看次数

如何将 Raku Grammar 标记固定为仅在字符串末尾时匹配

我已经写了这个 - 效果很好:

use Grammar::Tracer;

my grammar Lambda {
    token  TOP       { <signature> <body> ' as ' <r-type> }
    rule  signature { '|' <a-sig> [',' <b-sig>]? '|' }
    rule  a-sig     { 'a:' <a-type> }
    rule  b-sig     { 'b:' <b-type> }
    token body      { '(' <expr> ')' <?before ' as '> }
    token expr      { <-[()]>* }
    token a-type    { @types }
    token b-type    { @types }
    token r-type    { @types }
}

Lambda.parse("|a: i32, b: i32| (a + b) as …
Run Code Online (Sandbox Code Playgroud)

grammar raku

8
推荐指数
1
解决办法
108
查看次数

我怎样才能让这个 raku Muller Recurrence One-Liner 工作?

在对我最近的博客文章的回复中,Markus H. 回复了一个非常简洁的代码替代方案,即:

dd $_ for (4, 4.25, 108 – (815 – 1500 / * ) / * … *)[^30].kv
Run Code Online (Sandbox Code Playgroud)

可悲的是,我无法让它“开箱即用”并得到这个错误:

Confused
at /Users/stephenroe/Dropbox/RakuStuff/mullerrec/./mullerrec3.raku:27
------> dd $_ for (4, 4.25, 108? – (815 – 1500 / * ) / * … *)[^30].kv
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

这是我可以开始工作的代码(是的,我的风格有点不同,但没关系):

sub f(\y,\z) { 
    108 - ( (815 - 1500/z ) / y ) 
}
dd $_ for (4, 4.25, -> \z,\y …
Run Code Online (Sandbox Code Playgroud)

math raku

7
推荐指数
1
解决办法
102
查看次数

在`polars::prelude::DataFrame`中找不到lazy()方法

我正在 Rust 中为 Polars 编写一个外部库(供Raku::Dan使用),并且想通过调用 df.lazy() 为 LazyFrame 对象获取一个不透明容器。

use polars::prelude::*;//{CsvReader, DataType, DataFrame, Series};
use polars::prelude::{Result as PolarResult};
use polars_lazy::prelude::*;

// LazyFrame Container

pub struct LazyFrameC {
    lf: LazyFrame,
}

impl LazyFrameC {
    fn new(ptr: *mut DataFrameC) -> LazyFrameC {
        LazyFrameC {
            lf: (*ptr).df.lazy(),
        }
    }
}
// extern functions for LazyFrame Container
#[no_mangle]
pub extern "C" fn lf_new(ptr: *mut DataFrameC) -> *mut LazyFrameC {
    let df_c = unsafe {
        assert!(!ptr.is_null());
        &mut *ptr
    };

    Box::into_raw(Box::new(LazyFrameC::new(ptr)))
}
Run Code Online (Sandbox Code Playgroud)

不起作用,给出错误:

error[E0599]: …
Run Code Online (Sandbox Code Playgroud)

rust raku rust-polars

7
推荐指数
1
解决办法
1423
查看次数