This comes from this issue in the Perl 6 documentation, on the differential treatment of colonpairs; while :a
is equivalent to a => True
, (:a:b)
is (a => True b => 1)
and :a:b
or :a :b
simply drops the second; colonpairs behave in a different way depending on where they are in the second or first position.
So I have looked at the QAST, which prints this:
- 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)
The main difference is that the first colonpair is - QAST::Op(callmethod new) <wanted> :a
, while the second is - QAST::Op(callmethod new) <wanted nosink> :b
, please note the nosink
. The, I guess, important part is where an implicit operator , is called; this operator sinks the first element. But I wonder why the effect of sinking is making the value in the Pair
equal to True
, while not sinking it makes it equal to 1
. Is that intended? Some side effect or something I can't really understand? None of the above?