-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy path136.scd
57 lines (52 loc) · 1.17 KB
/
136.scd
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
// 1. Function that takes no arguments
(
f = {
"something".postln;
};
f.value;
f.value;
f.value;
"";
)
// In other languages you would call
// the function f like this: f();
// Here we use .value instead.
// Another difference with other languages
// is that the function does not have a name.
// It just happens to be stored in variable f,
// the same way you could store a string or
// a number.
// 2. Function that takes an argument
(
f = {
arg n;
("something" + n).postln;
};
f.value(1);
f.value(3);
f.value(5);
"";
)
// You can declare arguments in two ways.
// One, you can use the keyword arg.
// You could also use vertical bars, like this: |n|
// To send arguments to a function, you enter them
// separated by commas and inside parenthesis right
// after value, like this: f.value(1, 3, "hello");
// 3. Function that takes arguments
// and returns a value
(
f = {
arg a, b;
a+b;
};
f.value(1, 6).postln;
f.value(3, 8).postln;
f.value(5, 2).postln;
"";
)
// Functions automatically return the last code
// you run in that function, so you don't need
// to use the keyword return, as you do in other
// languages. Here I just entered a+b; instead of
// return a+b;