- 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 functions
- Evaluating an anonymous function
- Functions with method foreach
- Prototypes
- Packages
- Gradual typing
- Generic prototypes
- Important metaobjects
- The CyanInterpreter prototype
Anonymous functions
Functions of Cyan are similar to blocks of Smalltalk or anonymous functions of other languages.A function is a literal object –- an object declared explicitly, without being cloned ofanother object. A function may take arguments and can declares local variables. The syntaxof a literal function is:
{ (: ParamRV 🙂 code }
A function is very similar to a method definition –- it can take parameters and return avalue. For example:
b = { (: Int x -> Int 🙂 ^ x*x };
declares a function that takes an Int parameter and returns the square of it. Symbol ^ isused for returning a value. However, to b is associated a function, not a return value, which depends of the parameter. Functions are objects and therefore they support methods.