soma.cell

Hello World

The simplest Soma program: a cell with one handler that prints a greeting.

Example 001 of the basic Soma programs: a small, commented program that teaches one thing. Every output below was printed by soma 3.2.4 when this page was built.

How it is built

The cell Hello has no face and no memory. Handlers: greet (line 15).

Generated from soma describe on this file.

The source

001_hello_world.cell

// ============================================================================
// 001 — Hello World
// ============================================================================
// The simplest Soma program: a cell with one handler that prints a greeting.
//
// Run:   soma run 001_hello_world.cell greet
// Expect: Hello, World!

// Every Soma program lives inside a "cell" — the fundamental unit of code.
// A cell has a name (here "Hello") and contains handlers defined with "on".
cell Hello {

    // "on" defines a signal handler — like a function you can call from outside.
    // This one takes no arguments and returns a String.
    on greet() {
        // print() writes to stdout
        print("Hello, World!")

        // The last expression or explicit return is the handler's return value
        return "Hello, World!"
    }
}

What the toolchain says

$ soma check 001_hello_world.cell
✓ All checks passed.
$ soma run 001_hello_world.cell greet
Hello, World!
Hello, World!