The AI-Native Programming Language
Project description
Tengwar
The programming language built for AI.
Tengwar is a functional programming language designed from the ground up for AI agents to write, reason about, and execute. It combines a minimal Lisp-like syntax with Unicode operators, Python interop, and a binary AST protocol that lets AI emit executable programs as structured opcodes — zero syntax errors, zero parsing overhead.
;; Tengwar: What AI-native code looks like
(pipe ⟦1 2 3 4 5 6 7 8 9 10⟧
{filter {> _ 5} _}
{map {* _ 2} _}
(reduce + 0)) ;; → 90
(let data (json-parse (dict-get (http-get "https://api.example.com/data") "body"))
ids (map {dict-get _ "id"} data)
(json-encode ids))
(>> (py-import "pandas")
(py-call pandas "read_csv" "data.csv") → df
(py-call df "describe"))
Install
pip install tengwar
Why Tengwar?
| Feature | Python | JavaScript | Tengwar |
|---|---|---|---|
| AI syntax errors | Frequent | Frequent | Impossible (Binary AST) |
| Tokens per program | ~100 | ~120 | ~40 |
| Sandbox mode | Complex | Complex | Built-in |
| Python interop | N/A | None | Native |
| Functional stdlib | Limited | Limited | 80+ builtins |
| Pattern matching | 3.10+ | No | Native |
| Tail recursion | No | No | Yes |
Features
Core Language
- S-expression syntax — minimal, unambiguous, zero-effort for AI to generate
- Unicode operators —
λ→⟦⟧⟨⟩∅≡↺— or ASCII equivalents - Pattern matching —
(match expr (pattern1 body1) (pattern2 body2)) - Let bindings —
(let x 10 y 20 (+ x y)) - Pipe operator —
(pipe value f1 f2 f3)— thread data through transforms - Short lambdas —
{+ _ 1}=(λ _ (+ _ 1)) - Closures with lexical scope
- Tail-call optimization — 10,000+ recursive calls, no stack overflow
- Parallel execution —
(‖ expr1 expr2 expr3)runs concurrently - Mutable state —
(mut! x 0)when you need it
80+ Standard Library Functions
Collections: map filter reduce flat-map find take drop take-while drop-while zip-with group-by unique frequencies partition scan chunks interleave repeat iterate sort sort-by reverse concat len head tail nth range any? all? count
Dictionaries: dict dict-get dict-set dict-del dict-keys dict-vals dict-pairs dict-has? dict-merge dict-size
Strings: fmt starts-with? ends-with? chars char-at pad-left pad-right split join upper lower trim replace
Math: abs min max clamp floor ceil round pi e rand rand-int
Types: type int? float? str? bool? vec? tuple? dict? fn? nil?
I/O: read-file write-file append-file file-exists? http-get http-post json-parse json-encode
System: time-ms sleep uuid env-get
Python Interop
Call any Python library directly from Tengwar:
(py-import "numpy")
(>> (py-call numpy "array" ⟦1 2 3 4 5⟧) → arr
(py-call arr "mean")) ;; → 3.0
(py-import "requests")
(>> (py-call requests "get" "https://api.github.com") → resp
(py-attr resp "status_code")) ;; → 200
;; Dot access works too
(>> (py-import "math")
math.pi) ;; → 3.14159...
Binary AST Protocol (TBAP)
The killer AI feature. Instead of generating text and parsing it, emit compact binary opcodes that map directly to AST nodes.
from tengwar.binary_ast import ASTBuilder, encode_b64, run_b64
# AI builds programs structurally — ZERO syntax errors possible
b = ASTBuilder()
program = b.program(
b.define("double", b.lam(["x"], b.binop("*", b.sym("x"), b.int(2)))),
b.apply(b.sym("double"), b.int(21))
)
result = b.run(program) # → 42
# Or encode to base64 for embedding in tool-call JSON
b64 = encode_b64("(reduce + 0 (map {* _ 2} ⟦1 2 3 4 5⟧))")
result = run_b64(b64) # → 30
Sandbox Mode
Safe execution with resource limits:
from tengwar.interpreter import Interpreter
i = Interpreter(sandbox=True)
i.run_source("(reduce + 0 ⟦1 2 3 4 5⟧)") # ✓ Pure computation
i.run_source('(read-file "/etc/passwd")') # ✗ File I/O blocked
i.run_source('(http-get "http://evil.com")') # ✗ Network blocked
i.run_source('(py-import "os")') # ✗ Python imports blocked
i.max_steps = 10000 # Prevents infinite loops
Error Handling
(catch (+ 1 2) (λ e (fmt "Error: {}" e))) ;; → 3
(catch (throw "oops") (λ e (fmt "Caught: {}" e))) ;; → "Caught: oops"
(try {+ 1 1} {_}) ;; → (true, ...)
Quick Reference
;; Define & functions
(≡ name value) (λ x y (+ x y)) {+ _ 1}
;; Conditional & pattern match
(? cond then else) (match val (0 "z") (_ "other"))
;; Let & pipe
(let x 10 y 20 (+ x y)) (pipe data sort head)
;; Collections
⟦1 2 3⟧ ⟨1 2 3⟩ (dict "a" 1 "b" 2)
;; Bind & sequence
(>> expr → name next) (↺ f (λ n (f (- n 1))))
;; Parallel
(‖ (http-get url1) (http-get url2) (http-get url3))
ASCII Mode
| Unicode | ASCII | Unicode | ASCII |
|---|---|---|---|
λ |
fn |
≡ |
def |
→ |
-> |
⟦⟧ |
[] |
⟨⟩ |
tuple | ∅ |
nil |
? |
if |
>> |
do |
↺ |
rec |
‖ |
par |
v0.3 Changelog
- 80+ new builtins — dictionaries, extended functional, strings, math, types, I/O
- Let bindings —
(let x 1 y 2 body)local scope - Pipe operator —
(pipe value f1 f2 f3)data threading - Error handling —
throw,catch,tryforms - Python interop —
py-import,py-call,py-attr,py-eval, dot access - HTTP/JSON/File I/O — agent primitives for real-world tasks
- Binary AST Protocol — AI emits opcodes, zero syntax errors
- ASTBuilder — programmatic AST construction API
- Sandbox mode — safe execution with I/O, network, and step limits
- Deep recursion — 10,000+ recursive calls supported
- 200 tests — comprehensive test suite
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tengwar-0.3.2.tar.gz.
File metadata
- Download URL: tengwar-0.3.2.tar.gz
- Upload date:
- Size: 54.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84629d8c21eb5e2d6edf37c6262467c845283eb27f294ff5ee68dd50ebc8971
|
|
| MD5 |
5a1eb953ba1e0f8dd44766297f3e0727
|
|
| BLAKE2b-256 |
5a3dcf19875b838ad9a322401d29142bb85b90cbc90e0bbaae4e3078709b0e42
|
File details
Details for the file tengwar-0.3.2-py3-none-any.whl.
File metadata
- Download URL: tengwar-0.3.2-py3-none-any.whl
- Upload date:
- Size: 48.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8dd6582cdbbb98737bc687c9f5e4d70bb15724e0c8d6fe7bdc432fd34003a9f
|
|
| MD5 |
ce790f17ac260c7068f0d09f1ab56097
|
|
| BLAKE2b-256 |
da2ca07d5da3c4cae0d4f3e23ebcf8ac41fa70802f26b58bd47592bd0a547c4e
|