100 Helloslanguages
Home / Languages / Ceylon

Ceylon

2011fraglet
jvmobject-orientedfunctional.ceylon
docker run --rm --platform="linux/amd64" 100hellos/ceylon:latest

MCP + fragletc

MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →

Ceylon is a JVM-based object-oriented and functional language first appearing in 2011.

Hello World

#!/usr/bin/env sh

cd /hello-world
compile_out=$(ceylon compile hello 2>&1) || { echo "$compile_out" >&2; exit 1; }
echo "$compile_out" | grep -v '^Note: Created module ' >&2
[ "$1" = "--" ] && shift
ceylon run hello/1.0.0 -- "$@"

Coding Guide

Language Version

Ceylon (latest via SDKMAN)

Execution Model

  • Compiled language that runs on the JVM
  • Code is compiled with ceylon compile then executed with ceylon run
  • Requires module structure (module.ceylon + source files)
  • Execution handled by wrapper script

Key Characteristics

  • Statically typed
  • Case-sensitive
  • Java-like syntax with modern features
  • Module-based architecture
  • shared keyword for public visibility
  • Entry point is shared void run() function

Fragment Authoring

Write valid Ceylon code. Your fragment should include:

  • You must include shared void run() { ... } in your fragment
  • You CAN define functions, classes, and other module-level constructs
  • Functions are defined at module level, then called from run()

This approach enables teaching the full range of Ceylon features.

Stdin and Args

  • Command-line arguments: process.arguments (sequence of String) — e.g. print("Args: ``" ".join(process.arguments)``");
  • Stdin: process.readLine() in a loop — returns String?; use while (exists line = process.readLine()) { ... } to read line-by-line

Available Modules

  • Standard Ceylon modules available via import <module>;
  • JVM interop available via import java.lang { ... }

Common Patterns

  • Print: print("message");
  • Variables: Integer x = 5; or value x = 5;
  • Strings: String msg = "Hello";
  • Arrays: Integer[] numbers = [1, 2, 3];
  • Functions: Define at module level, call from run()
  • String interpolation: print("Value: ``value``");

Examples

// Simple output
shared void run() {
    print("Hello, World!");
}
// Variables and calculations
shared void run() {
    Integer a = 5;
    Integer b = 10;
    Integer sum = a + b;
    print("Sum: ``sum``");
}
// Function definition (at module level)
String greet(String name) {
    return "Hello, ``name``!";
}

shared void run() {
    print(greet("Alice"));
}
// Arrays and loops
shared void run() {
    Integer[] numbers = [1, 2, 3, 4, 5];
    variable Integer sum = 0;
    for (n in numbers) {
        sum += n;
    }
    print("Array sum: ``sum``");
}
// Multiple helper functions
Integer add(Integer a, Integer b) {
    return a + b;
}

Integer multiply(Integer a, Integer b) {
    return a * b;
}

shared void run() {
    Integer result = multiply(add(2, 3), 4);
    print("Result: ``result``");
}
// String operations
shared void run() {
    String text = "Hello, World!";
    print("Length: ``text.size``");
    print("Uppercase: ``text.uppercased``");
    print("Contains 'World': ``text.contains("World")``");
}
// Conditionals
shared void run() {
    Integer score = 85;
    if (score >= 90) {
        print("Grade: A");
    } else if (score >= 80) {
        print("Grade: B");
    } else {
        print("Grade: C");
    }
}
// Iteration with indices
shared void run() {
    String[] fruits = ["apple", "banana", "cherry"];
    for (i -> fruit in fruits.indexed) {
        print("``i``: ``fruit``");
    }
}
// Command-line arguments
shared void run() {
    print("Args: ``" ".join(process.arguments)``");
}
// Stdin (line-by-line, e.g. echo "hello" | fragletc --vein=ceylon script.ceylon)
shared void run() {
    while (exists line = process.readLine()) {
        print(line.uppercased);
    }
}

Notes

  • Use backticks () for string interpolation: value ``
  • Variables are immutable by default; use variable keyword for mutable variables
  • Functions without shared are private to the module
  • Entry point must be shared void run()
  • Ceylon uses Integer (not int) and String (not string)

Fraglet Scripts

Ceylon Fortune

#!/usr/bin/env -S fragletc --vein=ceylon
shared void run() {
    print("Ceylon: the language that fixed Java's null and then went to the beach.");
}

Echo Args

#!/usr/bin/env -S fragletc --vein=ceylon
shared void run() {
    print("Args: ``" ".join(process.arguments)``");
}

Stdin Upper

#!/usr/bin/env -S fragletc --vein=ceylon
shared void run() {
    while (exists line = process.readLine()) {
        print(line.uppercased);
    }
}

Test

#!/usr/bin/env -S fragletc --vein=ceylon
shared void run() {
    hello();
}

Connections

influenced by

Container Info

image100hellos/ceylon:latest
build scheduleThursday
fragletenabled