Noob: don't understand usage of curly brackets in if-statement

Another key point is that SC has no flow of control structures.

It has only method calls. (Some method calls are treated specially by the compiler for speed, but if infinitely-fast processing were possible, we could do without that entirely: if could be defined by dispatching true and false separately as it does now, and while can be defined by tail recursion.)

A method has a receiver (for if, the receiver is the condition) and zero or more arguments. Note that this means, unlike the C/Java family, there is no “true block” and “false block” – in SC, if has arguments for the true or false values.

In every method call, the receiver and all arguments must be evaluated before they can be passed in. If an argument is written as a + 1 then it must do the addition before calling the method.

So what is the result of the expression ~wahr above? It’s a function: {|i| ("wahr" + i).postln}. So when you write if(something, ~wahr), the environment variable is evaluated, resolving to the function, and then the function is passed into if, where it acts like a block to be evaluated conditionally.

What is the result of the expression ~wahr.value(1)? It is the string that was posted. The value call must be executed before calling if! So it is no longer a conditional.

What is the result of { ~wahr.value(1) }? A function containing the function call – which is passed in to be used as a conditional block.

hjh

2 Likes