Acronym / initials — first letter of each word, uppercased
"Portable Network Graphics" -> "PNG". Splits on spaces, drops empties, and collects the uppercased first character of each word. Demonstrates building a result by accumulating substring(w, 0, 1) over a filtered word list. Run: soma run acronym.cell --signal acronym "Portable Network Graphics"
A Soma program from the text part of the verified corpus: 43 lines, cells Acronym, AcronymTest. It passes soma check with soma 3.2.4.
How it is built
The cell Acronym declares 2 signals in its face: acronym(phrase: String) -> String and initials(name: String) -> String. Handlers: acronym (line 17) and initials (line 27).
The file also holds 1 test cell (AcronymTest) with 5 assertions, run by soma test.
The source
acronym.cell
// ============================================================================
// Acronym / initials — first letter of each word, uppercased
// ============================================================================
//
// "Portable Network Graphics" -> "PNG". Splits on spaces, drops empties, and
// collects the uppercased first character of each word. Demonstrates building
// a result by accumulating substring(w, 0, 1) over a filtered word list.
//
// Run: soma run acronym.cell --signal acronym "Portable Network Graphics"
cell Acronym {
face {
signal acronym(phrase: String) -> String
signal initials(name: String) -> String
}
on acronym(phrase: String) {
let words = split(phrase, " ") |> filter(w => len(w) > 0)
let out = ""
for w in words {
out = out + uppercase(substring(w, 0, 1))
}
return out
}
// Initials with dot separators: "Ada Lovelace" -> "A.L."
on initials(name: String) {
let words = split(name, " ") |> filter(w => len(w) > 0)
let parts = words |> map(w => uppercase(substring(w, 0, 1)) + ".")
return join(parts, "")
}
}
cell test AcronymTest {
rules {
assert acronym("Portable Network Graphics") == "PNG"
assert acronym("as soon as possible") == "ASAP"
assert acronym(" spaced out words ") == "SOW"
assert initials("Ada Lovelace") == "A.L."
assert initials("grace brewster hopper") == "G.B.H."
}
}What the toolchain says
$ soma check acronym.cell
warning: `out` grows by concatenation inside a loop — each step copies the whole value, so the loop is quadratic (8 MB took 32 s, a list + join() 30 ms): push the pieces to a List and `join(parts, "")` once
--> acronym.cell:21:13
|
21 | out = out + uppercase(substring(w, 0, 1))
| ^
✓ 1 warning(s), no errors.$ soma test acronym.cell
test AcronymTest ...
✓ assert acronym("Portable Network Graphics") == "PNG"
✓ assert acronym("as soon as possible") == "ASAP"
✓ assert acronym(" spaced out words ") == "SOW"
✓ assert initials("Ada Lovelace") == "A.L."
✓ assert initials("grace brewster hopper") == "G.B.H."
5 tests: 5 passed, 0 failed$ soma verify acronym.cell
Verifying acronym.cell...
No state machine in this program: nothing to prove beyond `soma check` (invariants and lifecycles are what verify proves).
VERIFY OK (vacuous — no state machine)