On 10/6/05, TomD <tomdiscus@xxxxxxxxxxx> wrote:
So is there any difference between "or:" and "||" (as with "and:" and
"&&") ?
There is a difference, but it's subtle. The difference is not in the
result, but in the internals. (If there were a different result, it
would be a bug.)
In the second example (using or:), the 2nd test is inlined and it will
run slightly faster. For that reason alone, I think it's better than
|| but in reality, it won't make much difference unless you're doing
it in a long loop.
hjh
{ if((a == 0) || {"2nd test".postln; 0.5.coin}) { "true".postln }
{"false".postln };
}.def.dumpByteCodes
BYTECODES: (22)
0 12 PushInstVar 'a'
1 63 PushSpecialValue 0
2 E6 SendSpecialBinaryArithMsg '=='
/* SECOND TEST IS HERE non-inlined func is pushed on the stack */
3 04 01 PushLiteralX instance of FunctionDef in closed
FunctionDef
/* END SECOND TEST */
5 A2 00 SendMsg '||'
7 F8 00 07 JumpIfFalse 7 (17)
10 41 PushLiteral "true"
11 B0 TailCallReturnFromFunction
12 C1 39 SendSpecialMsg 'postln'
14 FC 00 04 JumpFwd 4 (21)
17 40 PushLiteral "false"
18 B0 TailCallReturnFromFunction
19 C1 39 SendSpecialMsg 'postln'
21 F2 BlockReturn
{ if((a == 0) or: {"2nd test".postln; 0.5.coin}) { "true".postln }
{"false".postln };
}.def.dumpByteCodes
BYTECODES: (28)
0 12 PushInstVar 'a'
1 63 PushSpecialValue 0
2 E6 SendSpecialBinaryArithMsg '=='
/* SECOND TEST IS HERE inlined func gets rolled out */
3 FB 00 07 JumpIfTruePushTrue 7 (13)
6 40 PushLiteral "2nd test"
7 C1 39 SendSpecialMsg 'postln'
9 F0 Drop
10 66 PushSpecialValue 0.5
11 0D 2C SendSpecialUnaryArithMsgX 'coin'
/* END SECOND TEST */
13 F8 00 07 JumpIfFalse 7 (23)
16 42 PushLiteral "true"
17 B0 TailCallReturnFromFunction
18 C1 39 SendSpecialMsg 'postln'
20 FC 00 04 JumpFwd 4 (27)
23 41 PushLiteral "false"
24 B0 TailCallReturnFromFunction
25 C1 39 SendSpecialMsg 'postln'
27 F2 BlockReturn
--
James Harkins /// dewdrop world
jamshark70@xxxxxxxxxxxxxxxxx
http://www.dewdrop-world.net
"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman
_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users