soma.cell

Memory Properties

Memory slots can have different property combinations that declare durability, consistency, and visibility semantics.

Example 097 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 DataStore declares 2 signals in its face: read(key: String) -> String and write(key: String, value: String) -> String; keeps 3 memory slots: critical (Map<String, String>, persistent and consistent), cache (Map<String, String>, ephemeral and local) and secrets (Map<String, String>, persistent and encrypted). Handlers: read (line 28) and write (line 37).

Generated from soma describe on this file.

The source

097_memory_properties.cell

// ============================================================================
// 097 — Memory Properties
// ============================================================================
// Memory slots can have different property combinations that declare
// durability, consistency, and visibility semantics.
//
// Run:   soma check 097_memory_properties.cell
// Expect: All checks passed.

cell DataStore {
    face {
        signal read(key: String) -> String
        signal write(key: String, value: String) -> String
        promise "critical data is always persistent"
    }

    memory {
        // Persistent + consistent: survives restarts, reads reflect latest write
        critical: Map<String, String> [persistent, consistent]

        // Ephemeral + local: in-memory cache, lost on restart
        cache: Map<String, String> [ephemeral, local]

        // Encrypted: marks sensitive data — NOT encrypted at rest by this runtime (use an encrypted volume)
        secrets: Map<String, String> [persistent, encrypted]
    }

    on read(key: String) {
        // Try cache first, fall back to persistent store
        let cached = cache.get(key)
        if cached != () {
            return cached
        }
        return critical.get(key)
    }

    on write(key: String, value: String) {
        critical.set(key, value)
        cache.set(key, value)
        return value
    }
}

What the toolchain says

$ soma check 097_memory_properties.cell
note: promise on 'DataStore' is documentation (not machine-verifiable): "critical data is always persistent"
  --> 097_memory_properties.cell:14:17
   |
14 |         promise "critical data is always persistent"
   |                 ^
✓ All checks passed (1 note above).