Blocks
Gosu blocks are a special type of function that you can define in-line within another function. You can then pass that block of code to yet other functions to invoke as appropriate. Blocks are useful for generalizing algorithms and simplifying interfaces to certain APIs. For example, blocks can simplify tasks related to collections, such as finding items within or iterating across all items in a collection.
The following code illustrates the syntax of a Gosu block. It also illustrates the simple
use of a block. The example code multiples a number by itself, which is known as
squaring a
number:
var square = \ x : int-> x * x // No need for braces here
var myResult = square(10) // Call the blockThe value of myResult in this example is 100.
