anonymous functions

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.