jjm*_*elo 6 abstract-syntax-tree perl6
这来自Perl 6文档中关于结肠对差别处理的这个问题 ; 而:a等同于a => True,(:a:b)是(a => True b => 1)和/ :a:b或:a :b简单地放下第二个; colonpairs以不同的方式表现,取决于它们在第二或第一位置的位置.所以我看了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)
Run Code Online (Sandbox Code Playgroud)
主要区别在于第一个结肠对是- QAST::Op(callmethod new) <wanted> :a,而第二个是- QAST::Op(callmethod new) <wanted nosink> :b,请注意nosink.我猜,重要的部分是调用隐式运算符的地方; 此运算符会吸收第一个元素.但我想知道为什么下沉的效果使得价值Pair等于True,而不是下沉使其等于1.这是有意的吗?有些副作用还是我无法理解的东西?以上都不是?