|
|
|
|
|
by stchacademy
2072 days ago
|
|
Basically, the idea behind "?" is "functions that return a boolean". But done in a consistent way. So, practically EVERY function that returns a boolean is - by convention - terminated with a "?". Now, why the two "if"s: Obviously, as you yourself mentioned, 'if? returns a boolean (the result of the condition) and 'if doesn't. So that's one use. The next use - which I will obviously have to make crystal clear in the Language Reference - is that if? (with the ?) is a must if you want to pair with an "else". Think of it this way. If?-else may appear as a language construct, but in fact they are two separate commands. The if? is an if - that pushes the result of the condition of the stack. And "else" is actually a reversed-if: it checks what is at the top of the stack (see: returned by the if? above) and if that is false - that is: the above if-condition was not true - it executes its block. So, in that case, you have to use an "if?" (and not a simple "if") The same thing happens with a case/when? construct (only, in that case, the condition blocks are actually concatenated),e .g. case [x]
when? [<3] [print "it was less than 3"]
when? [=3] [print "it was equal to 3"]
else [ print "it was greater than 3"] :) :) |
|