Lema Lema

The Lema programming language

From low level to high

Build up low level primitives working with bits and bytes or write high level business rules. The same principles and composable guarantees apply.

Low-level cryptography

Prove byte-level and 32-bit word laws for standard primitives like RFC 8439 ChaCha20-Poly1305 authenticated encryption.

High-level business rules

Build on checked libraries in the same Pythonic syntax. An escrow contract keeps every unit accounted for across state transitions.

ChaCha20-Poly1305 · RFC 8439 AEADPythonic
law aead_roundtrip_checked(key: ByteArray, nonce: ByteArray,
                           aad: ByteArray, pt: ByteArray, ct: ByteArray):
    requires sealChecked(key, nonce, aad, pt) == some(ct)
    ensures openChecked(key, nonce, aad, ct) == some(pt)
Escrow · conservation of fundsPythonic
law conservation(a: Nat, b: Nat, s: State):
    requires Reachable(a, b, s)
    ensures s.a + s.b + escrow(s) == a + b

Lema setup prompt

Install Lema 0.3.2 and run its HTTPS echo starter on my machine. Comment on your experience as you go.

Use only public instructions and downloads from https://www.lema-lang.org/docs/tutorials/get-started/ and its linked setup/requirements pages. Do not assume access to the Lema source repository or ask me to install Rust.

## Check this machine

- Inspect the operating system, architecture, existing Lema installations and PATH. Use the published qualified Apple Silicon macOS or Linux x86_64 requirements. On another host, report the limitation before installing anything.
- Preserve existing projects, runtime configuration and unrelated services. Create the echo project in a new directory; if that name exists, choose a separate directory rather than overwrite it.
- Install or reuse the documented OpenSSL and TLS 1.3 curl tools. On Linux, bubblewrap must come from the OS package manager at /usr/bin/bwrap. Do not weaken ownership, sandbox or quarantine checks.

## Install and set up Lema

Use one public method. If Homebrew is already the preferred package manager, use:
brew tap lorenalabs/lema https://brew.lema-lang.org/homebrew-lema.git
if brew help trust >/dev/null 2>&1; then
  brew trust --formula lorenalabs/lema/lema
fi
brew install lorenalabs/lema/lema

Otherwise download and run the public installer:
curl --proto '=https' --tlsv1.2 -fsSLo install-lema.sh https://www.lema-lang.org/install.sh
sh install-lema.sh

Follow its printed PATH instruction. Keep lema and lema-vm-runner paired. Run lema --version, lema build-info --check-worker, then lema setup. Report the installed version and location, selected runtime configuration, worker check and library-pack result. Continue only when setup exits successfully and prints setup complete. Report a failed download or runtime check; do not silently use --no-pack to get past it.

## Run and test HTTPS

Run lema new echo in the chosen parent directory, enter the new echo project, then run lema run echo. Wait for the serving line, which follows the worker's bind, and copy the exact curl command Lema prints. On macOS this may use an absolute Homebrew curl path. Send the request twice and confirm both return POST /hello, request headers and hi.

The request uses --noproxy '*', HTTP/1.1 and TLS 1.3, with -k only for the local self-signed development certificate. Do not write TCP, TLS or HTTP framing code yourself. If the port is occupied, report it and choose a free development port with lema dev-cert echo --port PORT; do not kill an unrelated process.

## Exercise the edit loop and hand over

Stop the app with Ctrl-C. Change the successful branch of respond in Handler.lean to return Hello from Lema followed by a newline, as shown in the tutorial. Run lema add Handler.lean, then lema test Handler.report with the tutorial's explicit --expect oracle including that newline. Restart lema run echo, wait for serving, and repeat the printed request to confirm the changed response.

Leave the app running when successful. Give me its URL, project path and stop instructions, and explain that Ctrl-C stops the app while lema stop manages the background codebase server. Summarize installed tools, versions, locations, PATH changes and any remaining blockers. Distinguish what Lean checked from what these requests and the handler test exercised. Explain the explicit app/server restart needed after an update.