soma.cell

String Interpolation

Soma strings support {variable} interpolation, including map field access.

Example 006 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 Interpolation has no face and no memory. Handlers: run (line 15).

Generated from soma describe on this file.

The source

006_string_interpolation.cell

// ============================================================================
// 006 — String Interpolation
// ============================================================================
// Soma strings support {variable} interpolation, including map field access.
//
// Run:   soma run 006_string_interpolation.cell run
// Expect:
//   Hello, Alice!
//   Alice is 30 years old
//   User: Alice ([email protected])
//   Score: 95/100

cell Interpolation {

    on run() {
        // Simple variable interpolation
        let name = "Alice"
        print("Hello, {name}!")

        // Multiple variables in one string
        let age = 30
        print("{name} is {age} years old")

        // Map field access works inside interpolation
        let user = map("name", "Alice", "email", "[email protected]")
        print("User: {user.name} ({user.email})")

        // Expressions must be pre-computed into variables
        // (function calls don't work directly in interpolation)
        let score = 95
        let max_score = 100
        print("Score: {score}/{max_score}")

        return "done"
    }
}

What the toolchain says

$ soma check 006_string_interpolation.cell
✓ All checks passed.
$ soma run 006_string_interpolation.cell run
Hello, Alice!
Alice is 30 years old
User: Alice ([email protected])
Score: 95/100
done