/usr/share/SuperCollider/HelpSource/Reference/if.schelp is in supercollider-common 1:3.8.0~repack-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | title:: if
categories::Core, Common methods
related:: Reference/Control-Structures
summary:: conditional execution
method:: if
section::example
code::
if ( [false, true].choose, // Boolean expression (chooses one at random)
{ "expression was true".postln }, // true function
{ "expression was false".postln } // false function
)
(
var a = 1, z;
z = if (a < 5, { 100 },{ 200 });
z.postln;
)
::
UGens can also use if
the condition ugen is 0 / 1
code::
(
{
if( LFNoise1.kr(1.0,0.5,0.5) , SinOsc.ar, Saw.ar )
}.play
)
::
section:: optimization
the functions will be inlined, which plucks the code from the functions and uses a more efficient jump statement.
code::
{
if( 6 == 9,{
"hello".postln;
},{
"hello".postln;
})
}.def.dumpByteCodes
BYTECODES: (18)
0 FE 06 PushPosInt 6
2 FE 09 PushPosInt 9
4 E6 SendSpecialBinaryArithMsg '=='
5 F8 00 06 JumpIfFalse 6 (14)
8 42 PushLiteral "hello"
9 A1 00 SendMsg 'postln'
11 FC 00 03 JumpFwd 3 (17)
14 41 PushLiteral "hello"
15 A1 00 SendMsg 'postln'
17 F2 BlockReturn
a FunctionDef in closed FunctionDef
::
failure to inline due to variable declarations
code::
{
if( 6 == 9,{
var notHere;
"hello".postln;
},{
"hello".postln;
})
}.def.dumpByteCodes
WARNING: FunctionDef contains variable declarations and so will not be inlined.
in file 'selected text'
line 4 char 14 :
var notHere;•
"hello".postln;
-----------------------------------
BYTECODES: (12)
0 FE 06 PushPosInt 6
2 FE 09 PushPosInt 9
4 E6 SendSpecialBinaryArithMsg '=='
5 04 00 PushLiteralX instance of FunctionDef in closed FunctionDef
7 04 01 PushLiteralX instance of FunctionDef in closed FunctionDef
9 C3 0B SendSpecialMsg 'if'
11 F2 BlockReturn
a FunctionDef in closed FunctionDef
::
code::
{
if( 6 == 9,{
"hello".postln;
},{
"hello".postln;
})
}.def.dumpByteCodes
BYTECODES: (18)
0 FE 06 PushPosInt 6
2 FE 09 PushPosInt 9
4 E6 SendSpecialBinaryArithMsg '=='
5 F8 00 06 JumpIfFalse 6 (14)
8 42 PushLiteral "hello"
9 A1 00 SendMsg 'postln'
11 FC 00 03 JumpFwd 3 (17)
14 41 PushLiteral "hello"
15 A1 00 SendMsg 'postln'
17 F2 BlockReturn
a FunctionDef in closed FunctionDef
::
|