Gosu statements
A Gosu expression has a value, but Gosu statements do not. The result of a Gosu expression can be passed as an argument to a function. A Gosu statement does not have a result that can be passed as an argument to a function.
For example, the following lines are all Gosu expressions as each results in a value:
5 * 6
typeof 42
exists (var e in Claim.Exposures where e == null)
The following lines are all Gosu statements:
print(x * 3 + 5)
for (i in 10) { ... }
if (a == b) { ... }
See also
Statement lists
A statement list is a list containing zero
or more Gosu statements enclosed by braces ({}).
The Gosu standard is always to omit semicolon characters at the ends of lines of Gosu code. Code is more readable without optional semicolons. In the rare cases in which you type multiple statement lists on one line, such as within block definitions, do use semicolons to separate statements.
Syntax
{ statement-list }Multi-line example (no semicolons)
{
var x = 0
var y = myfunction( x )
print( y )
}Single-line example (semicolons)
var adder = \ x : int, y : int -> { print("I added!"); return x + y; }See also
Using the operator new as a statement
Use the new
operator to instantiate an object. Although it is often used as an expression,
new can also be a statement.
For some types, this functionality may not be useful. However, if the
constructor for the object triggers code that saves a copy of the new
object, the return value from new
may be unnecessary. Ignoring the return value and using new as a statement may permit
more concise code in these cases.
For example, suppose that a constructor for a class that represents a book registers itself with a bookshelf object and saves the new object. Some code might merely create the book object and pass the bookshelf as a constructor argument:
new gw.example.Book( bookshelfReference, author, bookID )See also
