Build from Source

Lambda Prelude is built from OCaml source with dune.

# Requires: OCaml 5.2+ (verified on 5.5), dune 3.0+, menhir 2.1+
git clone <repo-url> lambda_prelude
cd lambda_prelude
dune build

On Windows, the binary is a true native MinGW-w64 executable — no Cygwin DLL at runtime. Source disclosure is under NDA; please get in touch before evaluating for production.

Hello, Prelude

Create hello.lp:

'Hello, Lambda Prelude!' displayNl.

Run it under the interpreter:

lambda-prelude run hello.lp

Build it as a native binary:

lambda-prelude build hello.lp --out hello
./hello

The interpreter is for iteration. The AOT binary is the semantic record — when interpreter and AOT disagree, the AOT binary wins.

A Counter Class

Lambda Prelude is functional: values are immutable and classes do not declare instance variables. Each object is an immutable record over fields:.

Object subclass: #Counter fields: (value).

Counter class >> of: n = Counter fields: { value: n }.
Counter >> value = value.
Counter >> inc   = Counter fields: { value: value + 1 }.

c := Counter of: 41.
c inc value displayNl.   "=> 42"

inc returns a new Counter. There is no := reassignment in user code — the only binding form is let, written as := at top-level statements.

Branching is Polymorphic Dispatch

There is no if/match at the surface. Branching is done through messages:

(score > 90)
  ifTrue:  ['A' displayNl]
  ifFalse: ['B' displayNl].

name ifPresent: [:n | n displayNl]
     ifAbsent: ['anonymous' displayNl].

xs ifEmpty:    ['empty list' displayNl]
   ifNotEmpty: [:h :t | h displayNl].

This is the same convention used by traditional Smalltalk, applied uniformly: every conditional, every option / list destructuring, every retry / timeout branch is a message send.

Protocols Replace Inheritance

Classes do not inherit. Shared behaviour is expressed as Protocols, which act like type classes. A class declares the protocols it satisfies in its protocols: clause.

Protocol subclass: #Comparable
  requires: (#<).

Comparable >> > other  = other < self.
Comparable >> min: o   = (self < o) ifTrue: [self] ifFalse: [o].
Comparable >> max: o   = (self < o) ifTrue: [o]    ifFalse: [self].

Object subclass: #Score
  fields:    (points)
  protocols: (Comparable).

Score class >> of: n   = Score fields: { points: n }.
Score >> points        = points.
Score >> < other       = points < other points.

((Score of: 10) max: (Score of: 3)) displayNl.

Score implements <; >, min:, and max: come from Comparable for free.

Two Execution Modes

The same source runs two ways. They share the standard library, the type system, and the actor model.

CapabilityinterpreterAOT
Tree-walk for development iterationyes—
Direct OCaml calls for statically resolvable sends—yes
Runtime dispatcher for dynamic sendsyesyes
Multi-domain work-stealing scheduleryesyes
Plugins via Dynlink (PostgreSQL, MariaDB, MySQL, Redis)yesyes

Use run for iteration. Use build for production — the AOT binary lowers statically resolvable sends to direct OCaml calls and routes the rest through runtime method dispatch.

CLI Reference

lambda-prelude run    script.lp                     # tree-walk interpreter
lambda-prelude build  script.lp --out binary        # AOT to native
lambda-prelude test   tests                         # run Test API specs
lambda-prelude new    my-service                    # scaffold a project

Debug tooling:

lambda-prelude run   script.lp --trace-mailbox   # log every mailbox enqueue / receive
lambda-prelude run   script.lp --quiet           # suppress unmatched-message + actor-death reports
lambda-prelude run   script.lp --scheduler multi 4  # N-worker domain pool + auto-distribute
lambda-prelude build script.lp --deferred        # list the sends whose receiver type is left open
lambda-prelude build script.lp --emit            # print the lowered OCaml to stdout
lambda-prelude build script.lp --out script.ml   # write the lowered OCaml to a file

Modules and Files

One file is one module. A file does not declare its own name; its path decides it — the program's own file is Main, mylib.lp is MyLib, stdlib/terios/rpc.lp is Terios::Rpc. The header at the top of a file is two lines at most.

imports: (Http, MyLib).
exports: (Server, opaque Session).

A name in imports: is looked for in the importing file's own directory, then in the directories listed in LAMBDA_PRELUDE_PATH, then in stdlib. The separator is the platform's PATH separator (; on Windows, : on POSIX). A single-segment name with no .lp of its own (Torm, say) resolves to a plugin. The importing side has to spell the name the found file's path gives it.

LAMBDA_PRELUDE_PATH=src lambda-prelude run tests/my_test.lp   # a test in tests/ importing modules from src/

run, build, the language server and the debug adapter share one loader, so a name that resolves for run resolves for build and in the editor. A resolution failure lists the directories that were actually tried.

A class is identified by its module and its name (Shapes::Square), so when a bare name reaches two imported modules, Shapes::Square says which. A class not listed in exports: cannot be named from outside — see Design for the rest.

A Method Body is One Expression

A method body is a single expression. Work that has to run in order is written ( a. b. c ) — the sequence expression, whose statements run in order and whose value is the last one's.

Service >> handle: req = (
  Log info: 'start'.
  res := self compute: req.
  Log info: 'done'.
  res
).

The parser reads it as a block of those statements sent value, so nothing downstream — inference, AOT — changes at all. A name bound with := inside it is visible only within that sequence. ( e ) around a single expression stays plain grouping.

Editor

The VS Code extension (lambda-prelude) contributes syntax highlighting, a language server (parse and type-error diagnostics, hover showing inferred types, completion, go-to-definition, find references, rename), and a debug adapter (breakpoints, stepping, and variable inspection, running on the interpreter). Hover answers for the innermost expression the cursor is inside, and names type variables 'a, 'b, ... by first appearance rather than by the inferencer's serial numbers. Positions are counted in UTF-16 as the protocol specifies, so a line holding Japanese text points and renames correctly.

Definition, references and rename follow what a name refers to rather than its spelling — a local by its scope, a method through the resolution the type checker recorded. A protocol's selector and its implementations are renamed together as one group, as are an override and the method it overrides. The reach extends to the other files that import the edited one, and the editor's unsaved buffers are read in place of the disk.

A rename that cannot be done completely is refused rather than done in part, with the places that block it named: a send left to run time, a symbol that may be a perform: selector, a builtin or standard-library or synthesized method, a file that does not type-check, or a new name that would collide with another. The rewritten files are analysed again before the answer comes back.

The extension bundles the language server, the debug adapter, stdlib and the plugins, so a workspace with no build artefacts of its own still gets imports: and dao: resolved in its diagnostics. Settings: lambdaPrelude.importPath (the LAMBDA_PRELUDE_PATH equivalent; relative entries are taken from the workspace root, and it reaches the language server, the debug adapter and the Run command alike), and serverPath / cliPath / debugAdapterPath to point at binaries other than the bundled ones.

Next Steps