Define a block

A block defines an in-line function. For example, a block named square multiplies a value by itself and returns the result.

Procedure

  1. Start with the \ character.
  2. Optionally add a list of arguments as name:type pairs.
  3. Add the -> characters, which mark the beginning of the block’s body.
  4. Finally, add either a statement list surrounded by braces: { and }, or a Gosu expression.

Example

The following block multiplies a number with itself to square the number:

var square = \ x : Integer-> x * x // No need for braces for expressions, but must use for statements
var myResult = square(10)          // Call the block

The value of myResult in this example is 100.