Ceylon M1

Version of implementation Ceylon of programming language Ceylon

Ceylon M1 “Newton” is the first release of Ceylon compiler and IDE, released on December 20th, 2011.

Examples:

Hello, World! - Ceylon (418):

Let’s say we want this code to belong to helloworld.progopedia.com module. Then it has to be placed in a file /source/com/progopedia/helloworld.ceylon (the path is relative to the main directory of the program). Besides, a file named /source/com/progopedia/module.ceylon has to contain module description, for example, this one:

Module module {
 name = 'com.progopedia.helloworld';
 version = '1.0.0';
 by = {"Mariia Mykhailova"};
 dependencies = {};
 doc = "Hello, World!";
 license = 'Public domain';
}

Once the files are filled out, the program can be compiled with command ceylonc com.progopedia.helloworld and executed with ceylon com.progopedia.helloworld/1.0.0 (noting the version explicitly is a must).

void run() {
    print("Hello, World!");
}

Factorial - Ceylon (419):

This example calculates factorials iteratively. variable keyword points out that the value of the variable fact is going to be changed later (exactly the opposite of Java keyword final). Integer data type allows to store values of factorial without overflow. The arguments of print are concatenated without any explicit operator, but for this the first and the last elements of the list to be concatenated have to be string literals.

void run() {
    variable Integer fact := 1;
    for (i in 0..16) {
        print("" i "! = " fact "");
        fact *= i + 1;
    }
}

Fibonacci numbers - Ceylon (420):

This example calculates Fibonacci numbers iteratively.

void run() {
    variable String output := "";
    variable Integer fib1 := 0;
    variable Integer fib2 := 1;
    variable Integer fib3;
    for (i in 1..16) {
        output := "" output "" fib2 ", ";
        fib3 := fib1 + fib2;
        fib1 := fib2;
        fib2 := fib3;
    }
    print("" output "...");
}