|
|
|
|
|
by Supermancho
1337 days ago
|
|
Stylesheet on documentation is screwing up >= symbols under ; more comparisons and in other places, in chrome. The language is already so spatially dense/verbose, why use the full word "function" when fn would do? Strange that sometimes expressions are in parens and other times sqbrackets: when? [>2] -> print "1 is greater than 2. what?!"
when? [<0] -> print "1 is less than 0. nope..."
Some things make me do a double take, where consistent style will dictate one way to do something, but will be an endless hassle to watch out for the other: a: (2 > 3)["yes"]["no"] ; a: "no"
a: (2 > 3)? -> "yes" -> "no" ; a: "no" (exactly the same as above)
|
|
Basically, in Arturo, the two things are totally different:
- with parentheses, all you do is prioritize the evaluation of a given expression - now square brackets denote a block (of values) - one of the most basic building blocks of Arturo. And a block is not to be evaluated until we need it.
The case of `?` (which is an alias to the function `switch`) may look somewhat weird, but it follows Arturo's rules 100%. Have a look at the documentation: https://arturo-lang.io/documentation/library/core/switch/
Basically, the "normal", straightforward syntax would be:
``` a: switch 2 > 3 ["yes"]["no"] ```
Now, `-> "yes"` and `["yes"]` are exactly the same. All `->` does is wrap a single, computable value into a block (it's syntactic sugar, nothing more).
Now, why would we need parentheses in your example? (as you see, in mine, none was needed, as the order of evaluation is pretty much obvious)
if we did it without parentheses, given Arturo's right-to-left evaluation rule, it would mean something like: check if 3, if it's true, return "yes", otherwise return "no" and then compare that with 2. That's why we need the parentheses. But it's because `?` (switch alias) acts as an infix operator.
https://arturo-lang.io/documentation/language/#the-right-to-...