- Installing
- Hello World
- Spaces
- Identation
- Basics
- Comments
- Output
- ++ method
- Assignments and types
- Operator Precedence
- String interpolation
- Input
- Simple arithmetic
- Multiline strings
- Assert
- Arrays and literal arrays
- Literal intervals
- If, for, while and repeat-until
- Message sends
- Conversion between basic type values
- Anonymous function
- Evaluating an anonymous function
- Functions with method foreach
- Prototypes
- Packages
- Gradual typing
- Generic prototypes
- Important metaobjects
- The CyanInterpreter prototype
Functions with method foreach
Functions are useful to iterate over collections. For example,
var v = [ 1, 2, 3, 4, 5, 6 ]; // sum all elements of vector v var sum = 0; v foreach: { (: Int x :) sum = sum + x };
Method foreach: of the array v calls the function (as in “g eval: 5″, in the previous section) for each of the array elements.