- Installing
- Hello World
- Spaces
- Identation
- Basics
- Comments
- Output
- ++ method
- Assignments and types
- Operator Precedence
- String interpolation
- Input
- Simple arithmetic
- Multiline strings
- Assert
- Arrays and literals 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
An assignment is made with = as in
x = expr;
At runtime, the object that results from the evaluation of expr is assigned to x. At compile time, the type of x must be a supertype of the type of expr.
Assignments can be also done at variable declarations. The type of the variable will be the compile-time type of expr.
var x = expr;
Cyan has one basic type, starting with an upper case letter, for each of the basic types of Java: Byte, Short, Int, Long, Float, Double, Char, and Boolean. Besides that, there are prototypes Nil and String, also considered basic types. Nil will be explained later.
Cyan literals of Int, Double, and Char are defined as in Java. Byte, Short, and Long literals should end with B or Byte, S or Short, and L or Long, respectively as in
var aByte = 7B; var aShort = 29Short; var aLong = 1234567L; var bLong = 37Long; var anInt = 223Int;
Integral literal numbers without a postfixed letter are considered as having type Int. Numbers with a dot such as 10.0 as considered as Double. Float literals can end with F or Float. Double literals should end with D or Double (not needed if there is a ‘.’ but use D or Double if none, as in 10D or 10Double). There is no automatic conversion between types:
var Int age; var Byte byte0; var Float height; var Double width; // each of the lines below result in a compilation error
byte0 = 0; // use 0B, OB or 0 asByte age = byte0; // use byte0 asInt height = 1.0; // should be 1.0F width = 1; // 1.0, 1.0D, 1.0Double or 1 asDouble