Created
April 6, 2011 09:53
-
-
Save iani/905410 to your computer and use it in GitHub Desktop.
Partial Application and argument * and ... in SuperCollider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//:n Normal way to define a function | |
f = { | i | i.squared } | |
f ! 5 | |
[ 0, 1, 4, 9, 16 ] | |
//:p Partial application | |
g = _.squared; | |
a Function | |
g ! 5 | |
[ 0, 1, 4, 9, 16 ] | |
//:d Doc | |
// "_.squared" is the same as: { | i | i.squared } | |
//See help file Partial-Application.html for full doc. | |
// More examples: | |
//:2 arguments | |
g = Point(_, _); | |
g.value(100, 200); | |
//:4 arguments | |
h = Rect(_, _, _, _); | |
h.value(100, 200, 500, 240).postln; | |
// But! | |
i = Rect(*_); | |
(Array.rand(12, 0, 1000).clump(4) collect: i).postln; | |
//:* What about the star | |
f = { | arg1, arg2, arg3 | postf("arg1 is: %, arg2 is: %, arg3 is: %\n", arg1, arg2, arg3) }; | |
f.(100).postln; | |
f.(100, 200, 300).postln; | |
f.([100, 200, 300]).postln; | |
f.(*[100, 200, 300]).postln; | |
g = f.(*_); | |
Array.rand(12, 0, 1000).clump(3) do: g; | |
//:. The opposite of * is ... | |
f = { | ... coords | Rect(*coords).postln }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment