Parentheses

From MiniScript Wiki
Revision as of 21:06, 20 February 2020 by JoeStrout (talk | contribs)
Jump to navigation Jump to search

Parentheses in MiniScript have only three uses:

1. Use them to group math operations in the order you want them, just as in algebra.

x = (2+4)*7   // this is different from 2+4*7

2. Use them around the arguments in a function call, except when the function call is the entire statement.

print cos(0)   // parens needed; cannot just say: print cos 0

3. Use them when declaring a function.

Since other languages often require parentheses in many other places, it’s worth pointing out where parentheses are not used in MiniScript. First, don’t put parentheses around the condition of an if or while statement. Second, parentheses are not needed (and should be omitted) when calling a function without any arguments. For example, there is a time function that gets the number of seconds since the program began. It doesn’t need any arguments, so you can invoke it without parentheses.

x = time

Finally, as mentioned above, you don't need parentheses around the arguments of a function that is the very first thing on a statement.

Example

The following example prints ten numbers, waiting one second each, and then prints a message. Notice how print and wait are called without any parentheses. But the range call, because it has arguments and is used as part of a larger statement, parentheses are needed.

for i in range(10, 1)
  print i
  wait
end for
print "Boom!"