【发布时间】:2018-12-14 19:11:53
【问题描述】:
约束显然不用于在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
这意味着它使用的是第一个 multi,而不是第二个。但是,这按预期工作:
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 );
打印程序本身的内容。这可能说明了类型检查和多调度,但我不确定这是设计使然还是只是一个怪癖。有什么想法吗?
【问题讨论】:
-
想必你想使用文件名作为路径,所以我会使用
: ( IO(Str) $file where .f )