Source Code

The Ceylon language module containing the core types referred to in the language specification.

By: Gavin King, Tom Bentley, Tako Schotanus, Stephane Epardaud, Enrique Zamudio
License: http://www.apache.org/licenses/LICENSE-2.0.html
Packages
ceylon.language

The Ceylon language package.

ceylon.language.metamodel

The Ceylon language package.

By: Gavin King, Tom Bentley, Tako Schotanus, Stephane Epardaud, Enrique Zamudio
Attributes
emptySource Code
shared empty empty

A sequence with no elements, abbreviated []. The unique instance of the type [].

emptyIteratorSource Code
shared emptyIterator emptyIterator

An iterator that returns no elements.

equalSource Code
shared equal equal

The value is exactly equal to the given value.

By: Gavin
falseSource Code
shared false false

A value representing falsity in Boolean logic.

By: Gavin
finishedSource Code
shared finished finished

A value that indicates that an Iterator is exhausted and has no more values to return.

See also: Iterator
infinitySource Code
shared Float infinity = 1.0/0.0;

An instance of Float representing positive infinity ∞.

languageSource Code
shared language language

Contains information about the language

By: The Ceylon Team
largerSource Code
shared larger larger

The value is larger than the given value.

By: Gavin
nothingSource Code
shared Nothing nothing

A value that is assignable to any type, but that results in an exception when evaluated. This is most useful for generating members in an IDE.

nullSource Code
shared null null

The null value.

By: Gavin
processSource Code
shared process process

Represents the current process (instance of the virtual machine).

By: Gavin, Tako
smallerSource Code
shared smaller smaller

The value is smaller than the given value.

By: Gavin
trueSource Code
shared true true

A value representing truth in Boolean logic.

By: Gavin
Methods
abstractSource Code
shared Null abstract()

Annotation to mark a class as abstract. An abstract class may not be directly instantiated. An abstract class may have enumerated cases.

actualSource Code
shared Null actual()

Annotation to mark a member of a type as refining a member of a supertype.

anySource Code
shared Boolean any(Iterable<Boolean,Null> values)

Determines if any one of the given boolean values (usually a comprehension) is true.

See also: every
arraySource Code
shared Array<Element> array<Element>(Iterable<Element,Null> elements)

Create an array containing the given elements. If no elements are provided, create an empty array of the given element type.

arrayOfSizeSource Code
shared Array<Element> arrayOfSize<Element>(Integer size, Element element)

Create an array of the specified size, populating every index with the given element. If the specified size is smaller than 1, return an empty array of the given element type.

Parameters:
  • size

    The size of the resulting array. If the size is non-positive, an empty array will be created.

  • element

    The element value with which to populate the array. All elements of the resulting array will have the same value.

bySource Code
shared Null by(Sequential<String> authors)

Annotation to specify API authors.

byDecreasingSource Code
shared Comparison byDecreasing<Element, Value>(Value comparable(Element e))(Element x, Element y)
given Value satisfies Comparable<Value>

A comparator which orders elements in decreasing order according to the Comparable returned by the given comparable() function.

See also: byIncreasing
byIncreasingSource Code
shared Comparison byIncreasing<Element, Value>(Value comparable(Element e))(Element x, Element y)
given Value satisfies Comparable<Value>

A comparator which orders elements in increasing order according to the Comparable returned by the given comparable() function.

See also: byDecreasing
byItemSource Code
shared Comparison byItem<Item>(Comparison comparing(Item x, Item y))(Entry<Object,Item> x, Entry<Object,Item> y)
given Item satisfies Object

A comparator for Entrys which compares their items according to the given comparing() function.

See also: byKey
byKeySource Code
shared Comparison byKey<Key>(Comparison comparing(Key x, Key y))(Entry<Key,Object> x, Entry<Key,Object> y)
given Key satisfies Object

A comparator for Entrys which compares their keys according to the given comparing() function.

See also: byItem
classNameSource Code
shared String className(Object obj)

Return the name of the concrete class of the given object.

coalesceSource Code
shared Iterable<Element&Object,Null> coalesce<Element>(Iterable<Element,Null> values)

Return a sequence containing the given values which are not null. If there are no values which are not null, return an empty sequence.

Parameters:
  • values

    The values, some of which may be null.

combineSource Code
shared Iterable<Result,Absent> combine<Result, Absent, Element, OtherElement>(Result combination(Element element, OtherElement otherElement), Iterable<Element,Absent> elements, Iterable<OtherElement,Absent> otherElements)
given Absent satisfies Null

Applies a function to each element of two Iterables and returns an Iterable with the results.

By: Gavin, Enrique Zamudio, Tako
composeSource Code
shared Callable<X,Args> compose<X, Y, Args>(X(Y) x, Callable<Y,Args> y)
given Args satisfies Sequential<Anything>
countSource Code
shared Integer count(Iterable<Boolean,Null> values)

A count of the number of true items in the given values.

currySource Code
shared Callable<Return,Rest> curry<Return, Argument, First, Rest>(Callable<Return,Tuple<Argument,First,Rest>> f)(First first)
given First satisfies Argument
given Rest satisfies Sequential<Argument>
defaultSource Code
shared Null default()

Annotation to mark a member whose implementation may be refined by subtypes. Non-default declarations may not be refined.

deprecatedSource Code
shared Null deprecated(String? reason)

Annotation to mark program elements which should not be used anymore.

docSource Code
shared Null doc(String description)

Annotation to specify API documentation of a program element.

emptyOrSingletonSource Code
shared Sequential<Element> emptyOrSingleton<Element>(Element? element)
given Element satisfies Object

A Singleton if the given element is non-null, otherwise Empty.

See also: Singleton, Empty
entriesSource Code
shared Iterable<Entry<Integer,Element&Object>,Null> entries<Element>(Iterable<Element,Null> elements)

Produces a sequence of each index to element Entry for the given sequence of values.

equalToSource Code
shared Boolean equalTo<Element>(Element val)(Element element)
given Element satisfies Object

Returns a partial function that will compare an element to any other element and returns true if they're equal. This is useful in conjunction with methods that receive a predicate function.

everySource Code
shared Boolean every(Iterable<Boolean,Null> values)

Determines if every one of the given boolean values (usually a comprehension) is true.

See also: any
finalSource Code
shared Null final()

Annotation to mark a class as final. A final class may not be extended.

firstSource Code
shared Absent|Value first<Value, Absent>(Iterable<Value,Absent> values)
given Absent satisfies Null

The first of the given elements (usually a comprehension), if any.

flattenSource Code
shared Callable<Return,Args> flatten<Return, Args>(Return tupleFunction(Args tuple))
given Args satisfies Sequential<Anything>
forItemSource Code
shared Result forItem<Item, Result>(Result resulting(Item item))(Entry<Object,Item> entry)
given Item satisfies Object

A function that returns the result of the given resulting() function on the item of a given Entry.

See also: forKey
forKeySource Code
shared Result forKey<Key, Result>(Result resulting(Key key))(Entry<Key,Object> entry)
given Key satisfies Object

A function that returns the result of the given resulting() function on the key of a given Entry.

See also: forItem
formalSource Code
shared Null formal()

Annotation to mark a member whose implementation must be provided by subtypes.

greaterThanSource Code
shared Boolean greaterThan<Element>(Element val)(Element element)
given Element satisfies Comparable<Element>

Returns a partial function that will compare an element to any other element and returns true if the compared element is greater than its element. This is useful in conjunction with methods that receive a predicate function.

identicalSource Code
shared Boolean identical(Identifiable x, Identifiable y)

Determine if the arguments are identical. Equivalent to x===y. Only instances of Identifiable have well-defined identity.

Parameters:
  • x

    An object with well-defined identity.

  • y

    A second object with well-defined identity.

See also: identityHash
identityHashSource Code
shared Integer identityHash(Identifiable x)

Return the system-defined identity hash value of the given value. This hash value is consistent with identity equality.

See also: identical
joinSource Code
shared Sequential<Element> join<Element>(Sequential<Iterable<Element,Null>> iterables)

Given a list of iterable objects, return a new sequence of all elements of the all given objects. If there are no arguments, or if none of the arguments contains any elements, return the empty sequence.

Parameters:
  • iterables

    The iterable objects to join.

See also: SequenceBuilder
largestSource Code
shared Element largest<Element>(Element x, Element y)
given Element satisfies Comparable<Element>

Given two Comparable values, return largest of the two.

See also: Comparable, smallest, max
lateSource Code
shared Null late()

Annotation to disable definite initialization analysis for a reference.

lessThanSource Code
shared Boolean lessThan<Element>(Element val)(Element element)
given Element satisfies Comparable<Element>

Returns a partial function that will compare an element to any other element and returns true if the compared element is less than its element. This is useful in conjunction with methods that receive a predicate function.

licenseSource Code
shared Null license(String url)

Annotation to specify the URL of the license of a module or package.

maxSource Code
shared Absent|Value max<Value, Absent>(Iterable<Value,Absent> values)
given Value satisfies Comparable<Value>
given Absent satisfies Null

Given a nonempty sequence of Comparable values, return the largest value in the sequence.

See also: Comparable, min, largest
minSource Code
shared Absent|Value min<Value, Absent>(Iterable<Value,Absent> values)
given Value satisfies Comparable<Value>
given Absent satisfies Null

Given a nonempty sequence of Comparable values, return the smallest value in the sequence.

See also: Comparable, max, smallest
nativeSource Code
shared Null native()

Annotation to mark a member whose implementation is be provided by platform-native code.

optionalSource Code
shared Null optional()

Annotation to specify that a module can be executed even if the annotated dependency is not available.

parseFloatSource Code
shared Float? parseFloat(String string)

The Float value of the given string representation of a decimal number or null if the string does not represent a decimal number.

The syntax accepted by this method is the same as the syntax for a Float literal in the Ceylon language except that it may optionally begin with a sign character (+ or -).

parseIntegerSource Code
shared Integer? parseInteger(String string)

The Integer value of the given string representation of an integer, or null if the string does not represent an integer or if the mathematical integer it represents is too large in magnitude to be represented by an Integer.

The syntax accepted by this method is the same as the syntax for an Integer literal in the Ceylon language except that it may optionally begin with a sign character (+ or -).

plusSource Code
shared Value plus<Value>(Value x, Value y)
given Value satisfies Summable<Value>

Add the given Summable values.

See also: times, sum
printSource Code
shared void print(Anything line)

Print a line to the standard output of the virtual machine process, printing the given value's string, or «null» if the value is null.

This method is a shortcut for:

process.writeLine(line?.string else "«null»")

and is intended mainly for debugging purposes.

By: Gavin
productSource Code
shared Value product<Value>(Iterable<Value,Nothing> values)
given Value satisfies Numeric<Value>

Given a nonempty sequence of Numeric values, return the product of the values.

See also: sum
seeSource Code
shared Null see(Sequential<Anything> programElements)

Annotation to specify API references to other related program elements.

sharedSource Code
shared Null shared()

Annotation to mark a type or member as shared. A shared member is visible outside the block of code in which it is declared.

shuffleSource Code
shared Callable<Callable<Result,FirstArgs>,SecondArgs> shuffle<Result, FirstArgs, SecondArgs>(Callable<Callable<Result,SecondArgs>,FirstArgs> f)
given FirstArgs satisfies Sequential<Anything>
given SecondArgs satisfies Sequential<Anything>
smallestSource Code
shared Element smallest<Element>(Element x, Element y)
given Element satisfies Comparable<Element>

Given two Comparable values, return smallest of the two.

See also: Comparable, largest, min
sortSource Code
shared Sequential<Element> sort<Element>(Iterable<Element,Null> elements)
given Element satisfies Comparable<Element>

Sort the given elements, returning a new sequence.

See also: Comparable
stringSource Code
shared String string(Iterable<Character,Null> characters)

Create a new string containing the given characters.

sumSource Code
shared Value sum<Value>(Iterable<Value,Nothing> values)
given Value satisfies Summable<Value>

Given a nonempty sequence of Summable values, return the sum of the values.

See also: product
taggedSource Code
shared Null tagged(Sequential<String> tags)

Annotation to categorize the API by tag.

throwsSource Code
shared Null throws(Anything type, String? when)

Annotation to mark a program element that throws an exception.

timesSource Code
shared Value times<Value>(Value x, Value y)
given Value satisfies Numeric<Value>

Multiply the given Numeric values.

See also: plus, product
uncurrySource Code
shared Callable<Return,Tuple<Argument,First,Rest>> uncurry<Return, Argument, First, Rest>(Callable<Return,Rest> f(First first))
given First satisfies Argument
given Rest satisfies Sequential<Argument>
unflattenSource Code
shared Return unflatten<Return, Args>(Callable<Return,Args> flatFunction)(Args args)
given Args satisfies Sequential<Anything>
variableSource Code
shared Null variable()

Annotation to mark an value as variable. A variable value must be assigned multiple times.

zipSource Code
shared Sequential<Entry<Key,Item>> zip<Key, Item>(Iterable<Key,Null> keys, Iterable<Item,Null> items)
given Key satisfies Object
given Item satisfies Object

Given two sequences, form a new sequence consisting of all entries where, for any given index in the resulting sequence, the key of the entry is the element occurring at the same index in the first sequence, and the item is the element occurring at the same index in the second sequence. The length of the resulting sequence is the length of the shorter of the two given sequences.

Thus:

zip(xs,ys)[i]==xs[i]->ys[i]

for every 0<=i<min({xs.size,ys.size}).

Interfaces
BinarySource Code
shared Binary<Other>

Abstraction of numeric types that consist in a sequence of bits, like Integer.

CallableSource Code
shared Callable<out Return,in Arguments>

A reference to a function. The type arguments encode the function return type and parameter types. The parameter types are typically represented as a tuple type. For example, the type of the function reference plus<Float> is:

Callable<Float,[Float,Float]>

which we usually abbreviate Float(Float,Float). Any instance of Callable may be invoked by supplying a positional argument list:

Float(Float,Float) add = plus<Float>;
value four = add(2.0, 2.0);

or by supplying a tuple containing the arguments:

Float(Float,Float) add = plus<Float>;
[Float,Float] twoAndTwo = [2.0, 2.0];
value four = add(*twoAndTwo);

This interface may not be implemented by user code.

CategorySource Code
shared Category

Abstract supertype of objects that contain other values, called elements, where it is possible to efficiently determine if a given value is an element. Category does not satisfy Container, because it is conceptually possible to have a Category whose emptiness cannot be computed.

The in operator may be used to determine if a value belongs to a Category:

if ("hello" in "hello world") { ... }
if (69 in 0..100) { ... }
if (key->value in { for (n in 0..100) n.string->n**2 }) { ... }

Ordinarily, x==y implies that x in cat == y in cat. But this contract is not required since it is possible to form a meaningful Category using a different equivalence relation. For example, an IdentitySet is a meaningful Category.

CloneableSource Code
shared Cloneable<out Clone>

Abstract supertype of objects whose value can be cloned.

CloseableSource Code
shared Closeable

Abstract supertype of types which may appear as the expression type of a resource expression in a try statement.

CollectionSource Code
shared Collection<out Element>

Represents an iterable collection of elements of finite size. Collection is the abstract supertype of List, Map, and Set.

A Collection forms a Category of its elements.

All Collections are Cloneable. If a collection is immutable, it is acceptable that clone produce a reference to the collection itself. If a collection is mutable, clone should produce an immutable collection containing references to the same elements, with the same structure as the original collection—that is, it should produce an immutable shallow copy of the collection.

ComparableSource Code
shared Comparable<in Other>

The general contract for values whose magnitude can be compared. Comparable imposes a total ordering upon instances of any type that satisfies the interface. If a type T satisfies Comparable<T>, then instances of T may be compared using the comparison operators <, >, <=, >=, and<=>`.

The total order of a type must be consistent with the definition of equality for the type. That is, there are three mutually exclusive possibilities:

  • x<y,
  • x>y, or
  • x==y
ContainerSource Code
shared Container<out Element,out Absent = Null>

Deprecated: Will be removed in Ceylon 1.0.

Abstract supertype of objects which may or may not contain one of more other values, called elements, and provide an operation for accessing the first element, if any. A container which may or may not be empty is a Container<Element,Null>. A container which is always empty is a Container<Nothing,Null>. A container which is never empty is a Container<Element,Nothing>.

CorrespondenceSource Code
shared Correspondence<in Key,out Item>

Abstract supertype of objects which associate values with keys. Correspondence does not satisfy Category, since in some cases—List, for example—it is convenient to consider the subtype a Category of its values, and in other cases—Map, for example—it is convenient to treat the subtype as a Category of its entries.

The item corresponding to a given key may be obtained from a Correspondence using the item operator:

value bg = settings["backgroundColor"] else white;

The get() operation and item operator result in an optional type, to reflect the possibility that there is no item for the given key.

EmptySource Code
shared Empty

A sequence with no elements. The type Empty may be abbreviated [], and an instance is produced by the expression []. That is, in the following expression, e has type [] and refers to the value []:

[] none = [];

(Whether the syntax [] refers to the type or the value depends upon how it occurs grammatically.)

EmptyContainerSource Code

Deprecated: Will be removed in Ceylon 1.0.

An empty container.

EnumerableSource Code
shared Enumerable<out Other>

Abstraction of ordinal types whose instances can be mapped to the integers or to a range of integers.

ExponentiableSource Code
shared Exponentiable<This,Other>

Abstraction of numeric types that may be raised to a power. Note that the type of the exponent may be different to the numeric type which can be exponentiated.

IdentifiableSource Code

The abstract supertype of all types with a well-defined notion of identity. Values of type Identifiable may be compared using the === operator to determine if they are references to the same object instance. For the sake of convenience, this interface defines a default implementation of value equality equivalent to identity. Of course, subtypes are encouraged to refine this implementation.

IntegralSource Code
shared Integral<Other>

Abstraction of integral numeric types. That is, types with no fractional part, including Integer. The division operation for integral numeric types results in a remainder. Therefore, integral numeric types have an operation to determine the remainder of any division operation.

InvertableSource Code
shared Invertable<out Inverse>

Abstraction of types which support a unary additive inversion operation. For a numeric type, this should return the negative of the argument value. Note that the type parameter of this interface is not restricted to be a self type, in order to accommodate the possibility of types whose additive inverse can only be expressed in terms of a wider type.

IterableSource Code
shared Iterable<out Element,out Absent = Null>

Abstract supertype of containers whose elements may be iterated. An iterable container need not be finite, but its elements must at least be countable. There may not be a well-defined iteration order, and so the order of iterated elements may not be stable.

The type Iterable<Element,Null>, usually abbreviated {Element*} represents a possibly-empty iterable container. The type Iterable<Element,Nothing>, usually abbreviated {Element+} represents a nonempty iterable container.

An instance of Iterable may be constructed by surrounding a value list in braces:

{String+} words = { "hello", "world" };

An instance of Iterable may be iterated using a for loop:

for (c in "hello world") { ... }

Iterable and its subtypes define various operations that return other iterable objects. Such operations come in two flavors:

  • Lazy operations return a “view” of the receiving iterable object. If the underlying iterable object is mutable, then changes to the underlying object will be reflected in the resulting view. Lazy operations are usually efficient, avoiding memory allocation or iteration of the receiving iterable object.

  • Eager operations return an immutable object. If the receiving iterable object is mutable, changes to this object will not be reflected in the resulting immutable object. Eager operations are often expensive, involving memory allocation and iteration of the receiving iterable object.

Lazy operations are preferred, because they can be efficiently chained. For example:

string.filter((Character c) => c.letter)
      .map((Character c) => c.uppercased)

is much less expensive than:

string.select((Character c) => c.letter)
      .collect((Character c) => c.uppercased)

Furthermore, it is always easy to produce a new immutable iterable object given the view produced by a lazy operation. For example:

[ string.filter((Character c) => c.letter)
        .map((Character c) => c.uppercased)... ]

Lazy operations normally return an instance of Iterable or Map.

However, there are certain scenarios where an eager operation is more useful, more convenient, or no more expensive than a lazy operation, including:

  • sorting operations, which are eager by nature,
  • operations which preserve emptiness/nonemptiness of the receiving iterable object.

Eager operations normally return a sequence.

IteratorSource Code
shared Iterator<out Element>

Produces elements of an Iterable object. Classes that implement this interface should be immutable.

ListSource Code
shared List<out Element>

Represents a collection in which every element has a unique non-negative integer index.

A List is a Collection of its elements, and a Correspondence from indices to elements.

Direct access to a list element by index produces a value of optional type. The following idiom may be used instead of upfront bounds-checking, as long as the list element type is a non-null type:

value char = "hello world"[index];
if (exists char) { /*do something*/ }
else { /*out of bounds*/ }

To iterate the indexes of a List, use the following idiom:

for (i->char in "hello world".indexed) { ... }
MapSource Code
shared Map<out Key,out Item>

Represents a collection which maps keys to items, where a key can map to at most one item. Each such mapping may be represented by an Entry.

A Map is a Collection of its Entrys, and a Correspondence from keys to items.

The prescence of an entry in a map may be tested using the in operator:

if ("lang"->"en_AU" in settings) { ... }

The entries of the map may be iterated using for:

for (key->item in settings) { ... }

The item for a key may be obtained using the item operator:

String lang = settings["lang"] else "en_US";
NonemptyContainerSource Code
shared NonemptyContainer<out Element>

Deprecated: Will be removed in Ceylon 1.0.

A nonempty container.

NumberSource Code
shared Number

Abstraction of numbers. Numeric operations are provided by the subtype Numeric. This type defines operations which can be expressed without reference to the self type Other of Numeric.

NumericSource Code
shared Numeric<Other>

Abstraction of numeric types supporting addition, subtraction, multiplication, and division, including Integer and Float. Additionally, a numeric type is expected to define a total order via an implementation of Comparable.

OrdinalSource Code
shared Ordinal<out Other>

Abstraction of ordinal types, that is, types with successor and predecessor operations, including Integer and other Integral numeric types. Character is also considered an ordinal type. Ordinal types may be used to generate a Range.

RangedSource Code
shared Ranged<in Index,out Span>

Abstract supertype of ranged objects which map a range of Comparable keys to ranges of values. The type parameter Span abstracts the type of the resulting range.

A span may be obtained from an instance of Ranged using the span operator:

print("hello world"[0..5])
ScalarSource Code
shared Scalar<Other>

Abstraction of numeric types representing scalar values, including Integer and Float.

SequenceSource Code
shared Sequence<out Element>

A nonempty, immutable sequence of values. The type Sequence<Element>, may be abbreviated [Element+].

Given a possibly-empty sequence of type [Element*], the if (nonempty ...) construct, or, alternatively, the assert (nonempty ...) construct, may be used to narrow to a nonempty sequence type:

[Integer*] nums = ... ;
if (nonempty nums) {
    Integer first = nums.first;
    Integer max = max(nums);
    [Integer+] squares = nums.collect((Integer i) i**2));
    [Integer+] sorted = nums.sort(byIncreasing((Integer i) i));
}

Operations like first, max(), collect(), and sort(), which polymorphically produce a nonempty or non-null output when given a nonempty input are called emptiness-preserving.

SequentialSource Code
shared Sequential<out Element>

A possibly-empty, immutable sequence of values. The type Sequential<Element> may be abbreviated [Element*] or Element[].

Sequential has two enumerated subtypes:

  • Empty, abbreviated [], represents an empty sequence, and
  • Sequence<Element>, abbreviated [Element+] represents a non-empty sequence, and has the very important subclass Tuple.
SetSource Code
shared Set<out Element>

A collection of unique elements.

A Set is a Collection of its elements.

Sets may be the subject of the binary union, intersection, exclusive union, and complement operators |, &, ^, and ~.

SummableSource Code
shared Summable<Other>

Abstraction of types which support a binary addition operator. For numeric types, this is just familiar numeric addition. For strings, it is string concatenation. In general, the addition operation should be a binary associative operation.

Classes
AnythingSource Code
shared abstract Anything

The abstract supertype of all types. A value of type Anything may be a definite value of type Object, or it may be the null value. A method declared void is considered to have the return type Anything.

Note that the type Nothing, representing the intersection of all types, is a subtype of all types.

ArraySource Code
shared abstract Array<Element>

A fixed-size array of elements. An array may have zero size (an empty array). Arrays are mutable. Any element of an array may be set to a new value.

This class is provided primarily to support interoperation with Java, and for some performance-critical low-level programming tasks.

ArraySequenceSource Code
shared ArraySequence<out Element>

An immutable Sequence implemented using the platform's native array type. Where possible copying of the underlying array is avoided.

BasicSource Code
shared abstract Basic

The default superclass when no superclass is explicitly specified using extends. For the sake of convenience, this class inherits a default definition of value equality from Identifiable.

BooleanSource Code
shared abstract Boolean

A type capable of representing the values true and false of Boolean logic.

CharacterSource Code
shared abstract Character

A 32-bit Unicode character.

ComparisonSource Code
shared abstract Comparison

The result of a comparison between two Comparable objects.

EntrySource Code
shared Entry<out Key,out Item>

A pair containing a key and an associated value called the item. Used primarily to represent the elements of a Map. The type Entry<Key,Item> may be abbreviated Key->Item. An instance of Entry may be constructed using the -> operator:

String->Person entry = person.name->person;
FinishedSource Code
shared abstract Finished

The type of the value that indicates that an Iterator is exhausted and has no more values to return.

FloatSource Code
shared abstract Float

An IEEE 754 64-bit floating point number. A Float is capable of approximately representing numeric values between 2-1022 and (2-2-52)×21023, along with the special values infinity and -infinity, and undefined values (Not a Number). Zero is represented by distinct instances +0, -0, but these instances are equal. An undefined value is not equal to any other value, not even to itself.

IntegerSource Code
shared abstract Integer

A 64-bit integer, or the closest approximation to a 64-bit integer provided by the underlying platform.

  • For the JVM runtime, integer values between -263 and 263-1 may be represented without overflow.
  • For the JavaScript runtime, integer values with a magnitude no greater than 253 may be represented without loss of precision.

Overflow or loss of precision occurs silently (with no exception raised).

LazyListSource Code
shared LazyList<out Element>

An implementation of List that wraps an Iterable of elements. All operations on this List are performed on the Iterable.

LazyMapSource Code
shared LazyMap<out Key,out Item>

A Map implementation that wraps an Iterable of entries. All operations, such as lookups, size, etc. are performed on the Iterable.

LazySetSource Code
shared LazySet<out Element>

An implementation of Set that wraps an Iterable of elements. All operations on this Set are performed on the Iterable.

NullSource Code
shared abstract Null

The type of the null value. Any union type of form Null|T is considered an optional type, whose values include null. Any type of this form may be written as T? for convenience.

The if (exists ... ) construct, or, alternatively, the assert (exists ...) construct, may be used to narrow an optional type to a definite type, that is, a subtype of Object:

String? firstArg = process.arguments.first;
if (exists firstArg) {
    print("hello " + firstArg);
}

The else operator evaluates its second operand if and only if its first operand is null:

String name = process.arguments.first else "world";

The then operator evaluates its second operand when its first operand evaluates to true, and to null otherwise:

Float? diff = x>=y then x-y;
ObjectSource Code
shared abstract Object

The abstract supertype of all types representing definite values. Any two Objects may be compared for value equality using the == and != operators:

true==false
1=="hello world"
"hello"+ " " + "world"=="hello world"
Singleton("hello world")=={ "hello world" }

However, since Null is not a subtype of Object, the value null cannot be compared to any other value using ==. Thus, value equality is not defined for optional types. This neatly voids the problem of deciding the value of the expression null==null, which is simply illegal.

RangeSource Code
shared Range<Element>

Represents the range of totally ordered, ordinal values generated by two endpoints of type Ordinal and Comparable. If the first value is smaller than the last value, the range is increasing. If the first value is larger than the last value, the range is decreasing. If the two values are equal, the range contains exactly one element. The range is always nonempty, containing at least one value.

A range may be produced using the .. operator:

for (i in min..max) { ... }
if (char in `A`..`Z`) { ... }
SequenceAppenderSource Code
shared SequenceAppender<Element>

This class is used for constructing a new nonempty sequence by incrementally appending elements to an existing nonempty sequence. The existing sequence is not modified, since Sequences are immutable. This class is mutable but threadsafe.

SequenceBuilderSource Code
shared SequenceBuilder<Element>

Since sequences are immutable, this class is used for constructing a new sequence by incrementally appending elements to the empty sequence. This class is mutable but threadsafe.

SingletonSource Code
shared Singleton<out Element>

A sequence with exactly one element, which may be null.

StringSource Code
shared abstract String

A string of characters. Each character in the string is a 32-bit Unicode character. The internal UTF-16 encoding is hidden from clients.

A string is a Category of its Characters, and of its substrings:

'w' in greeting 
"hello" in greeting

Strings are summable:

String greeting = "hello" + " " + "world";

They are efficiently iterable:

for (char in "hello world") { ... }

They are Lists of Characters:

value char = "hello world"[5];

They are ranged:

String who = "hello world"[6...];

Note that since string[index] evaluates to the optional type Character?, it is often more convenient to write string[index..index], which evaluates to a String containing a single character, or to the empty string “” if index refers to a position outside the string.

The string() function makes it possible to use comprehensions to transform strings:

string(for (s in "hello world") if (s.letter) s.uppercased)

Since a String has an underlying UTF-16 encoding, certain operations are expensive, requiring iteration of the characters of the string. In particular, size requires iteration of the whole string, and get(), span(), and segment() require iteration from the beginning of the string to the given index.

StringBuilderSource Code

Since strings are immutable, this class is used for constructing a string by incrementally appending characters to the empty string. This class is mutable but threadsafe.

TupleSource Code
shared Tuple<out Element,out First,out Rest = []>

A tuple is a typed linked list. Each instance of Tuple represents the value and type of a single link. The attributes first and rest allow us to retrieve a value form the list without losing its static type information.

value point = Tuple(0.0, Tuple(0.0, Tuple("origin")));
Float x = point.first;
Float y = point.rest.first;
String label = point.rest.rest.first;

Usually, we abbreviate code involving tuples.

[Float,Float,String] point = [0.0, 0.0, "origin"];
Float x = point[0];
Float y = point[1];
String label = point[2];

A list of types enclosed in brackets is an abbreviated tuple type. An instance of Tuple may be constructed by surrounding a value list in brackets:

[String,String] words = ["hello", "world"];

The index operator with a literal integer argument is a shortcut for a chain of evaluations of rest and first. For example, point[1] means point.rest.first.

A terminated tuple type is a tuple where the type of the last link in the chain is Empty. An unterminated tuple type is a tuple where the type of the last link in the chain is Sequence or Sequential. Thus, a terminated tuple type has a length that is known statically. For an unterminated tuple type only a lower bound on its length is known statically.

Here, point is an unterminated tuple:

String[] labels = ... ;
[Float,Float,String*] point = [0.0, 0.0, *labels];
Float x = point[0];
Float y = point[1];
String? firstLabel = point[2];
String[] allLabels = point[2...];
emptySource Code
shared empty

A sequence with no elements, abbreviated []. The unique instance of the type [].

emptyIteratorSource Code

An iterator that returns no elements.

equalSource Code
shared equal

The value is exactly equal to the given value.

falseSource Code
shared false

A value representing falsity in Boolean logic.

finishedSource Code
shared finished

A value that indicates that an Iterator is exhausted and has no more values to return.

languageSource Code
shared language

Contains information about the language

largerSource Code
shared larger

The value is larger than the given value.

nullSource Code
shared null

The null value.

processSource Code
shared process

Represents the current process (instance of the virtual machine).

smallerSource Code
shared smaller

The value is smaller than the given value.

trueSource Code
shared true

A value representing truth in Boolean logic.

Exceptions
AssertionExceptionSource Code

An exception that occurs when an assertion fails, that is, when a condition in an assert statement evaluates to false at runtime.

ExceptionSource Code
shared Exception

The supertype of all exceptions. A subclass represents a more specific kind of problem, and may define additional attributes which propagate information about problems of that kind.

InitializationExceptionSource Code

Thrown when a problem was detected with value initialization.

Possible problems include:

  • when a value could not be initialized due to recursive access during initialization,
  • an attempt to use a late value before it was initialized,
  • an attempt to assign to a late but non-variable value after it was initialized.
NegativeNumberExceptionSource Code

Thrown when a negative number is not allowed.

OverflowExceptionSource Code

Thrown when a mathematical operation caused a number to overflow from its bounds.