gpt4 book ai didi

raku - 如何在 Perl 6 中返回上下文敏感的返回值?

转载 作者:行者123 更新时间:2023-12-03 23:54:34 24 4
gpt4 key购买 nike

differences的摘要中在 Perl 5 和 Perl 6 之间,需要注意的是 wantarray功能没了:

wantarray() is gone

wantarray is gone. In Perl 6, context flows outwards, which means that a routine does not know which context it is in.

Instead you should return objects that do the right thing in every context.



有人可以提供一个如何创建这样一个对象的例子吗?

最佳答案

我认为两个例子可能是:

http://perlcabal.org/syn/S13.html#Type_Casting

A class may define methods that allow it to respond as if it were a routine, array, or hash. The long forms are as follows:


method postcircumfix:<( )> ($capture) {...}
method postcircumfix:<[ ]> (**@slice) {...}
method postcircumfix:<{ }> (**@slice) {...}

Those are a bit unwieldy, so you may also use these short forms:


method &.( $capture ) {...}
method @.[ **@slice ] {...}
method %.{ **@slice } {...}

另外,我认为这可能是相关的,但不太相关: http://perlcabal.org/syn/S12.html

搜索:

You may write your own accessors to override any or all of the autogenerated ones.



因此,您返回一个具有多个特定于上下文的访问器的对象。

有趣的是,它开始于 Perl6 用通用的“want”替换“wantarray”: RFC 98 (v1) context-based method overloading, circa 2000 ,也在 http://dev.perl.org/perl6/rfc/21.html .我不确定为什么/何时进行更改。

关于raku - 如何在 Perl 6 中返回上下文敏感的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3962901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com