Note: information on this page refers to Ceylon 1.0, not to the current release.

Expressions

An expression produces a value when evaulated. Complex expressions may be constructed by recursively applying operators to simpler expressions. Only certain expressions can legally be used in expression statements.

Usage

Expressions are built using the following constructs.

Literals

String literals:

"hello, world"

String templates:

"Hello ``name``, good ``timeOfDay(now)``!";

Character literals:

'a'

Integer literals:

1

Floating point literals:

3.0

Self and outer references

Current instance reference:

this

Outer instance reference:

outer

Supertype reference:

super

// or sometimes
super of Foo

Containing package qualifier:

package

Invocation

Positional invocations:

print("Hello")

"hello world".initial(5)

Entry("one", 1)

Named argument invocations:

print {
    val = "Hello";
}

"hello, world".initial {
    length = 2;
}

Entry {
    item = 1;
    key = "one";
}

Iterable and tuple enumeration

Iterable enumeration:

{1, 2}

Tuple enumeration:

[1, 2]

Operators

x = 1

2 + 2

"hello world"[6..11]

0<=x<10

names.empty || !enabled

Further information.

References

These are callable references

print

String

These are static references

String.size

String.initial

Model references

These are model references:

`String`

`Sequential<String>`

`max<Integer, Null>`

`true`

`List<Integer>.size`

Declaration references

These are declaration references:

`class String`

`interface Sequential`

`function sum`

`value true`

`value List.size`

`package ceylon.language`

`module ceylon.language`

Description

The Ceylon compiler checks expressions for type safey at compile time.

See also