Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mcclowes/lea

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An image of code flowing down a symbolic river

Lea

A pipe-oriented functional programming language with a tree-walk interpreter written in TypeScript.

npm version Try Lea online

let numbers = [1, 2, 3, 4, 5]

let sumOfSquares = numbers
  /> filter((x) -> x > 2)
  /> map((x) -> x * x)
  /> reduce(0, (acc, x) -> acc + x)

sumOfSquares /> print  -- 50

Features

  • Pipes — Left-to-right data flow with /> operator
  • Functions — First-class, with optional type annotations
  • Decorators — Composable function modifiers (#log, #memo, #retry(3))
  • Records — Object literals with member access
  • Contexts — Dependency injection system
  • Async/Await — Promise-based asynchronous execution

Quick Start

# Clone and install
git clone https://github.com/mcclowes/lea.git
cd lea
npm install

# Run a file
npm run lea example.lea

# Interactive REPL
npm run repl

Syntax

Bindings

let x = 10              -- Immutable
maybe counter = 0       -- Mutable

Functions

let double = (x) -> x * 2
let add = (a, b) -> a + b

-- Type annotations (trailing :: syntax)
let typed = (x) -> x * 2 :: Int :> Int

-- Multi-statement bodies
let process = (x) ->
  let y = x * 2
  let z = y + 1
  z

Strict Mode

Enable strict type checking with #strict pragma or --strict CLI flag:

#strict

let add = (a, b) -> a + b :: (Int, Int) :> Int
add(5, 10)        -- OK: 15
add("a", "b")     -- Error: Argument 'a' expected Int, got string
npm run lea file.lea --strict

Pipes

16 /> sqrt              -- sqrt(16) = 4
5 /> add(3)             -- add(5, 3) — value becomes first arg
5 /> add(3, _)          -- add(3, 5) — placeholder controls position

-- Chain operations
[1, 2, 3, 4, 5]
  /> filter((x) -> x > 2)
  /> map((x) -> x * x)
  /> print

Records

let user = { name: "Max", age: 99 }
user.name /> print      -- "Max"

let nested = { data: { value: 42 } }
nested.data.value /> print

Decorators

Apply modifiers after function body:

let logged = (x) -> x * 2 #log
let cached = (x) -> expensiveOp(x) #memo
let resilient = (x) -> riskyOp(x) #retry(3) #timeout(1000)

Available decorators:

  • #log — Log inputs/outputs
  • #memo — Cache results
  • #time — Log execution time
  • #retry(n) — Retry on failure
  • #timeout(ms) — Fail if exceeds time
  • #validate — Runtime type checking
  • #pure — Warn on side effects
  • #async — Mark as async
  • #trace — Deep call logging

Context System

Dependency injection for functions:

-- Define context with default
context Logger = { log: (msg) -> print("[DEFAULT] " ++ msg) }

-- Override in scope
provide Logger { log: (msg) -> print("[PROD] " ++ msg) }

-- Attach to function
let greet = (name) ->
  @Logger
  Logger.log("Hello " ++ name)

"World" /> greet  -- "[PROD] Hello World"

Async/Await

let fetchData = () -> delay(100) #async
await fetchData() /> print

Documentation

Working with Claude

This repository includes Claude Code skills to help you write and modify Lea code effectively.

Available Skills

Skill Description
lea Use when writing or modifying Lea code — covers syntax, builtins, and interpreter internals
functional-programming Use when writing functional code — covers FP best practices (Lea differs from traditional FP languages)

Install with OpenSkills

OpenSkills is a CLI tool that makes it easy to install and manage Claude Code skills.

Step 1: Install OpenSkills

npm i -g openskills

Step 2: Install Skills

# Interactive mode
openskills install mcclowes/lea

# Or skip prompts
openskills install mcclowes/lea -y

Step 3: Sync (optional)

If you have an AGENTS.md file, sync to update configuration:

openskills sync

Installation Modes

  • Project-level (default): openskills install mcclowes/lea — installs to .claude/skills/
  • Global: openskills install mcclowes/lea -g — installs to ~/.claude/skills/

Architecture

Source → Lexer → Tokens → Parser → AST → Interpreter → Result
  • src/lexer.ts — Tokenization
  • src/parser.ts — Recursive descent parser
  • src/ast.ts — AST node definitions
  • src/interpreter.ts — Tree-walk interpreter
  • src/repl.ts — Interactive REPL

License

MIT

About

A pipe-oriented functional programming language with a tree-walk interpreter written in TypeScript.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •