u/TheHelgeSverre

Sema: prompts are s-expressions, conversations are data, LLMs are just evaluation
▲ 0 r/lisp

Sema: prompts are s-expressions, conversations are data, LLMs are just evaluation

Sema is a small Scheme-like Lisp in Rust. Messages, conversations, tools, agents, embeddings, structured extraction — all ordinary runtime values you compose, not external SDK glue.

The core is familiar: macros, modules, TCO, lexical scope, lists, vectors, maps, keywords, errors, the usual stdlib. Some Clojure-style ergonomics on top: :keywords, vector literals, map literals. Runs as a CLI/REPL, embeds as a Rust crate, runs in the browser via WebAssembly.

Plain Lisp first:

(define person {:name "Ada" :age 36})
(:name person)
; => "Ada"

(map #(* % %) (range 1 6))
; => (1 4 9 16 25)

(defmacro unless (test . body)
  `(if ,test nil (begin ,@body)))

Same idea on the LLM side — values you compose, not JSON blobs or string templates.

Chat messages are values:

(llm/chat
  (list (message :system "You are concise.")
        (message :user "Explain continuations in one sentence."))
  {:max-tokens 100})

Conversations are persistent data structures:

(define c (conversation/new {}))
(define c (conversation/say c "Remember: the secret number is 7."))
(define c (conversation/say c "What is the secret number?"))
(conversation/last-reply c)

Tools are Lisp functions with schemas:

(deftool lookup-capital
  "Look up the capital of a country"
  {:country {:type :string}}
  (lambda (country)
    (cond
      ((= country "Norway") "Oslo")
      ((= country "France") "Paris")
      (else "Unknown"))))

(llm/chat
  (list (message :user "What is the capital of Norway?"))
  {:tools (list lookup-capital)})

Structured extraction is schema-driven:

(llm/extract
  "Ada Lovelace was born in 1815 and worked on the Analytical Engine."
  {:name       {:type :string}
   :birth-year {:type :number}
   :known-for  {:type :string}})

Beyond that: vector search, response caching, fallback chains, retry/backoff, budget tracking, HTTP/JSON, SQLite, PDF extraction, a small web server. Multi-provider (Anthropic, OpenAI, Gemini, Ollama, Groq, xAI, Mistral, OpenAI-compatible).

Links:

u/TheHelgeSverre — 4 days ago