- 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
Message sends
In the following statement
var p = Person clone;
Person clone is sending the message clone to prototype Person and “clone” is called the “selector”of the message
p setName: name;
is the sending of message “setName: name” to the object referenced to byp. The message selector is“setName:” and “name” is the argument.
Out println: (p getName);
is the sending of message “println: (p getName)” to prototype Out. The message selector is “println:”and the argument is the object returned by “p getName”.
Cyan also supports keyword messages, a message with multiple keywords as in
var p = Point dist: 100.0 angle: 20.0;
Cyan calls dist: and angle: keywords. Following Smalltalk terminology, dist:angle: is called a “selector”
object Point func dist: (Float newDist) angle: (Float newAngle) -> Point { var p = self clone; p dist: newDist; p angle: newAngle; return p } public Float dist public Float angle end
After a single keyword there may be multiple parameters:
func p1: (Int x1, Int y1) p2: (Int x2, Int y2) p3: Int x3, Int y3 p4: Int x4, Int y4 { self.x = x1; . . }