Basic examples
97 small Soma programs, from hello world to a full application, each commented line by line and run when this page was built. Read them in order to learn the language; the verified corpus has the larger programs.
| # | Example | What it shows |
|---|---|---|
| 001 | Hello World | The simplest Soma program: a cell with one handler that prints a greeting. |
| 002 | Variables and Assignment | Demonstrates let bindings, reassignment, and string interpolation. |
| 003 | Basic Types | Soma has these built-in types: Int, Float, String, Bool, List, Map, and () () is null/unit. type_of() tells you what something is. |
| 004 | Arithmetic Operations | Demonstrates +, -, *, /, % on integers and floats. |
| 005 | String Operations | Demonstrates Soma's rich set of string built-in functions. |
| 006 | String Interpolation | Soma strings support {variable} interpolation, including map field access. |
| 007 | Null Handling | () is null in Soma. The ?? operator provides defaults for null values. |
| 008 | Type Conversions | Demonstrates to_string(), to_int(), to_float(), and to_json()/from_json(). |
| 009 | Booleans and Comparisons | Demonstrates boolean values and comparison operators. |
| 010 | Multiple Handlers | A cell can have multiple handlers. Each is like a public method. Handlers can call each other. |
| 011 | If / Else | Demonstrates conditional branching with if/else. |
| 012 | While Loops | Demonstrates the while loop for repeated execution. |
| 013 | For..In Loops | for..in iterates over List values. |
| 014 | Recursion | Handlers can call themselves recursively. |
| 015 | Nested Conditions and Complex Logic | Demonstrates deeply nested if/else for multi-factor decisions. |
| 016 | Loop Patterns | Common loop patterns: accumulator, find, early exit simulation. |
| 017 | FizzBuzz | The classic interview problem, implemented in Soma. |
| 018 | String Builder Pattern | Demonstrates building strings with += (append) and concat. |
| 019 | Number Algorithms | Classic number theory: GCD, primality test, collatz sequence. |
| 020 | Iterating Over Maps | Maps are iterated via .keys(), then accessing each value with .get(). |
| 021 | List Basics | Creating lists, accessing elements, appending, and getting length. |
| 022 | Map Basics | Creating maps, accessing fields, and using with/without/merge. |
| 023 | Nested Data Structures | Lists of maps, maps of lists — complex nested data. |
| 024 | List Transformations | Building new lists from existing ones with for loops. |
| 025 | Flatten and Zip | flatten() merges nested lists; zip() pairs up two lists. |
| 026 | Enumerate | enumerate() adds an index to each element of a list. |
| 027 | Pluck and Select | pluck() extracts a single field; select() picks multiple fields. |
| 028 | JSON Serialization | to_json() and from_json() for data serialization. |
| 029 | Memory Slots | Cells can have persistent memory using the memory { } block. Memory slots have properties like [persistent, consistent]. |
| 030 | Collection Algorithms | Higher-level operations: group_by, unique counting, frequency analysis. |
| 031 | Filter and Sort Pipelines | filter_by() and sort_by() are the building blocks of data pipelines. |
| 032 | The Pipe Operator |> | a |> f(b) is equivalent to f(a, b). Enables readable data pipelines. |
| 033 | Joining Datasets | join() and left_join() combine two lists on a shared key. |
| 034 | Aggregation with agg() | agg() groups by a field and computes aggregates (sum, avg, count, etc). |
| 035 | Sum, Avg, Min, Max | Convenience aggregation functions that work on a whole list. |
| 036 | Group By | group_by() partitions data; combine with iteration for analytics. |
| 037 | Multi-Stage Pipeline | Chaining multiple operations: filter -> join -> aggregate -> sort. |
| 038 | Top N Analysis | top() takes the first N rows from a (usually sorted) list. |
| 039 | Sales Dashboard Pipeline | A realistic multi-table analytics pipeline for sales data. |
| 040 | ETL Pipeline (Extract, Transform, Load) | Simulates an ETL workflow: extract raw data, transform it, load a summary. |
| 041 | Simple REST API | A minimal key-value API with put, get, delete. Serve: soma serve 041_simple_api.cell Test: curl localhost:8080/put/mykey/myvalue curl loca |
| 042 | CRUD API for Users | Full Create-Read-Update-Delete API using JSON serialization. Serve: soma serve 042_crud_api.cell Test: curl -X POST localhost:8080/create? |
| 043 | JSON API Responses | Demonstrates returning structured JSON from API handlers. |
| 044 | HTTP Status Codes | response() lets you set HTTP status codes for error handling. Serve: soma serve 044_status_codes.cell Test: curl localhost:8080/find/1 - |
| 045 | Input Validation | Validates input data and returns appropriate error responses. |
| 046 | Generic Request Handler | The special request(method, path, body) handler catches all HTTP requests. Serve: soma serve 046_request_handler.cell Test: curl localhost |
| 047 | Bookmarks API | A practical API for managing bookmarks with tags. |
| 048 | Search API | Filter and search through data using pipeline operators. |
| 049 | Counter API | A simple counter with increment, decrement, and get. Demonstrates memory slots and basic state management. Serve: soma serve 049_counter_ap |
| 050 | Notes API with Search | A notes API that supports creating, listing, and searching notes. |
| 051 | Static HTML Page | html() wraps content with the correct content-type for browsers. Use single quotes for HTML attributes (double quotes delimit Soma strings). |
| 053 | HTML Form Handling | Forms submit to signal handlers. GET forms use query parameters. Serve: soma serve 053_html_form.cell Test: open http://localhost:8080 -> |
| 054 | HTMX Counter | A counter that updates without page reloads using HTMX. Serve: soma serve 054_htmx_counter.cell Test: open http://localhost:8080 |
| 057 | Redirects | redirect() sends an HTTP redirect response to the browser. Serve: soma serve 057_redirect.cell Test: curl localhost:8080/old-page -> redir |
| 058 | HTML Partials (Component Pattern) | Break HTML into reusable handler-based components. |
| 059 | Multi-Page App with Routing | Route different paths to different pages using the request handler. Serve: soma serve 059_multi_page.cell Test: curl localhost:8080/ |
| 060 | Dashboard Page with Dynamic Data | Combines data processing with HTML rendering for a dashboard. |
| 061 | Basic State Machine | State machines define valid transitions. The compiler enforces them. |
| 062 | Ticket Tracking System | A support ticket system with state machine for ticket lifecycle. |
| 063 | Approval Workflow | A multi-stage approval process using state machines. |
| 064 | Document Lifecycle | Documents move through draft -> review -> published states. |
| 065 | E-Commerce Order Pipeline | Full order management: create, add items, process through stages. |
| 066 | Deployment Pipeline | CI/CD deployment stages modeled as a state machine. |
| 067 | Kanban Task Board | Tasks flow through: backlog -> todo -> in_progress -> done. |
| 068 | Subscription Lifecycle | Models a SaaS subscription: trial -> active -> cancelled etc. |
| 069 | Interview Process | Candidate moves through interview stages. |
| 070 | Querying Valid Transitions | valid_transitions() returns what states are reachable from the current one. |
| 071 | CSV-Like Data Processing | Parse and process tabular data represented as lists of maps. |
| 072 | Analytics Report | Multi-dimensional analytics on a dataset. |
| 073 | Report Generator | Builds a formatted text report from data. |
| 074 | Data Cleaning | Clean and normalize messy data. |
| 075 | Pivot Table | Summarize data across two dimensions (like a pivot table). |
| 076 | Text Histogram | Build a simple text-based histogram from data. |
| 077 | Moving Average | Compute a simple moving average over a series of values. |
| 078 | Leaderboard | Process game scores into a ranked leaderboard. |
| 079 | Data Merge (Multi-Source Join) | Combine data from multiple sources using joins. |
| 080 | ETL Transformation Pipeline | Extract data, apply multiple transformations, produce final output. |
| 081 | Blog Engine | A simple blog with posts and listing. |
| 082 | Contact Book | Manage contacts with search capability. |
| 083 | Inventory Management | Track products, quantities, and stock levels. |
| 084 | Invoice Generator | Create invoices with line items and compute totals. |
| 085 | Task Tracker | A project task tracker with priorities and assignment. |
| 086 | Expense Tracker | Track expenses by category and generate summaries. |
| 087 | Quiz Scoring | Score a quiz and provide a grade. |
| 088 | Recipe Book | Store and search recipes with ingredients. |
| 089 | URL Shortener | Shorten URLs and track visit counts. Serve: soma serve 089_url_shortener.cell |
| 090 | Polling / Voting System | Create polls, cast votes, see results. |
| 091 | BigInt Arithmetic | BigInt provides arbitrary-precision integers — no overflow. |
| 092 | Basic Tests | Tests are declared with `cell test Name { rules { assert ... } }`. |
| 093 | Testing String Functions | Test string manipulation with declarative assertions. |
| 094 | Testing Recursive Functions | Verify recursive algorithms with declarative tests. |
| 095 | Face Block and Promises | The face block declares a cell's public interface and promises. Promises are runtime-checked guarantees. |
| 096 | Custom Properties | Define custom properties that extend the memory system. The language grows — no compiler changes needed. |
| 097 | Memory Properties | Memory slots can have different property combinations that declare durability, consistency, and visibility semantics. |
| 098 | Multiple Cells in One File | A file can contain multiple cells. Each is an independent unit. Tests can reference handlers from non-test cells. |
| 099 | Comprehensive Example: Employee Directory | Combines multiple Soma features in one realistic application: - Memory with properties - Data pipelines with filter/sort/aggregate - String |
| 100 | Full Application: Product Catalog with State Machine | The capstone example: combines cells, state machines, pipelines, memory, tests, and HTML rendering in one file. |