This may look like the dumbest question of them all, but I can’t get my head around the following:
// please evaluate line by line
~wahr = {|i| ("wahr" + i).postln}; // a function
~falsch = {|i| ("falsch" + i).postln}; // a function
// EXAMPLE A
5.do({|i| if ( [false, true].choose, ~wahr, ~falsch)});
// works (but i is nil, as i is not handed over to functions, so this nil is expected)
// EXAMPLE B
5.do({|i| if ( [false, true].choose, ~wahr.(i), ~falsch.(i))});
// doesn't work, as both functions are executed (if statement is ignored), but why?
// EXAMPLE C
5.do({|i| if ( [false, true].choose, {~wahr.(i)}, {~falsch.(i)})});
//works, but why do I need to put the functions into curly brackets again?
In example B I don’t understand why just handing over the i
value to the functions all of sudden makes the whole thing ignore the if
statement.
And in example C I don’t understand why it works: Putting { }
around something makes it a function, and if I evaluate ~wahr
or ~falsch
on its own, post window returns “a function”. So when using these functions in the if
statement, why do I need to put these functions into { }
again? And why are these { }
not needed in A and B?
Thanks much in advance!