这来自this issue in the Perl 6 documentation,关于结肠对的区别对待; :a
等效于a => True
,而(:a:b)
等于(a => True b => 1)
,而:a:b
或:a :b
仅仅丢弃第二个;结肠对的行为根据其在第二或第一位置的不同而不同。
所以我看了QAST,它打印了这个:
- QAST::Block(:cuid(2)) :in_stmt_mod<?> #!/usr/bin/env perl6\n\nuse v6;\n\nsay (:a:b);\n
- QAST::Var(local __args__ :decl(param))
- QAST::Stmts #!/usr/bin/env perl6\n\nuse v6;\n\nsay (:a:b);\n
- QAST::Op(call)
- QAST::Block(:cuid(1) :blocktype(declaration_static)) :outer<?> :in_stmt_mod<?> :code_object<?> :IN_DECL<mainline>
- QAST::Stmts #!/usr/bin/env perl6\n\nuse v6;\n\nsay (:a:b);\n
- QAST::Var(lexical $¢ :decl(contvar))
- QAST::Var(lexical $! :decl(contvar))
- QAST::Var(lexical $/ :decl(contvar))
- QAST::Var(lexical $_ :decl(contvar))
- QAST::Var(lexical GLOBALish :decl(static))
- QAST::Var(lexical EXPORT :decl(static))
- QAST::Var(lexical $?PACKAGE :decl(static))
- QAST::Var(lexical ::?PACKAGE :decl(static))
- QAST::Var(lexical $=finish :decl(static))
- QAST::Var(lexical $=pod :decl(static))
[value]
-
- QAST::Var(lexical !UNIT_MARKER :decl(static))
- QAST::Stmts
- QAST::Op(bind)
- QAST::Var(local ctxsave :decl(var))
- QAST::Var(contextual $*CTXSAVE)
- QAST::Op(unless)
- QAST::Op(isnull)
- QAST::Var(local ctxsave)
- QAST::Op(if)
- QAST::Op(can)
- QAST::Var(local ctxsave)
- QAST::SVal(ctxsave)
- QAST::Op(callmethod ctxsave)
- QAST::Var(local ctxsave)
- QAST::Stmts
- QAST::WVal(Array)
- QAST::Stmts <sunk> ;\n\nsay (:a:b);\n
- QAST::Stmt <sunk final> say (:a:b)
- QAST::Want <sunk>
- QAST::Op(call &say) <sunk> :statement_id<2> say (:a:b)
- QAST::Stmts <wanted> (:a:b)
- QAST::Op(call &infix:<,>)
- QAST::Op(callmethod new) <wanted> :a
- QAST::Var(lexical Pair) <wanted> :a
- QAST::Want <wanted>
- QAST::WVal(Str)
- Ss
- QAST::SVal(a)
- QAST::Op(hllbool) <wanted>
- QAST::IVal(1)
- QAST::Op(callmethod new) <wanted nosink> :b
- QAST::Var(lexical Pair) <wanted> :b
- QAST::Want <wanted>
- QAST::WVal(Str)
- Ss
- QAST::SVal(b)
- QAST::Want <wanted>
- QAST::IVal(1)
- v
- QAST::Op(p6sink)
- QAST::Op(call &say) <sunk> :statement_id<2> say (:a:b)
- QAST::Stmts <wanted> (:a:b)
- QAST::Op(call &infix:<,>)
- QAST::Op(callmethod new) <wanted> :a
- QAST::Var(lexical Pair) <wanted> :a
- QAST::Want <wanted>
- QAST::WVal(Str)
- Ss
- QAST::SVal(a)
- QAST::Op(hllbool) <wanted>
- QAST::IVal(1)
- QAST::Op(callmethod new) <wanted nosink> :b
- QAST::Var(lexical Pair) <wanted> :b
- QAST::Want <wanted>
- QAST::WVal(Str)
- Ss
- QAST::SVal(b)
- QAST::Want <wanted>
- QAST::IVal(1)
- QAST::WVal(Nil)
主要区别在于,第一个冒号对是- QAST::Op(callmethod new) <wanted> :a
,而第二个是- QAST::Op(callmethod new) <wanted nosink> :b
,请注意nosink
。我想最重要的部分是隐式运算符的调用位置。此运算符下沉第一个元素。但是我想知道为什么下沉的效果是使Pair
中的值等于True
,而没有下沉的结果使其等于1
。那是故意的吗?一些副作用或我无法真正理解的东西?以上都不是吗?