File: if.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (115 lines) | stat: -rw-r--r-- 2,346 bytes parent folder | download | duplicates (6)
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
::