The Λ Language

Λ is the scripting language in document margins. It runs when a document is read.

Instructions

InstructionSyntaxEffect
saysay "text"Print. {var} substitution.
writewrite path "text"Append line to file
setset name "value"Set variable
set ←set name ← exprSet from expression
ifif cond:Conditional (indented block)
looploop:Infinite loop (indented block, 10K cap)
loop whileloop while cond:Conditional loop (indented block)
inscribeinscribe pathCreate file (indented = content)
withdrawwithdraw pathDelete file
erode selferode self NRemove N lines from own Μ text
mutate selfmutate self "old" "new"Replace text in own Μ layer
waitwait NsPause N seconds

Expressions

ExpressionReturns
count path/*Number of items in directory
read-countTimes this document was read
random-line pathRandom line from a file (xorshift PRNG)
random-choice path/Random filename from directory
ask "prompt"Reader's typed input

Conditions

FormTrue when
var > NGreater than
var < NLess than
var == "text"Equals
varNon-empty, not "0"

Built-in variables

VariableContains
{reader}Username
{time}HH:MM:SS
{date}YYYY-MM-DD
{documents-read}Session count
{read-count}This document's read count
{document}This document's name

Self-modification

Documents can modify their own Μ (text) layer:

Both operations preserve the --- Λ --- separator. The logic layer is never eroded.

The grid language

Beneath simple Λ is the full ΦΜΛ grid language — a two-dimensional esoteric programming language. Grid programs use inspect -deep to view. Simple Λ instructions compile conceptually down to grid operations, but you never need to touch the grid unless you want to.

Example


A greeting that remembers you.

--- Λ ---
set visits ← read-count
if visits == "1":
  say "Welcome, {reader}. First visit."
if visits > 1:
  say "Welcome back. Visit #{visits}."
set mood ← ask "How are you?"
say "Noted: {reader} is {mood}."
write west-wing/journal/{date} "{time} {reader}: {mood}"

Example with loop


A countdown timer.

--- Λ ---
set n "10"
loop while n > 0:
  say "{n}..."
  set n ← n - 1
  wait 1s
say "Done."