Sprout 3

Sprout compared

Sprout next to four languages, each at what it is known for: Python for being first, Rebol for literals and parsing, Clojure for data and sequences, Lua for tables, strings and coroutines. Every Sprout program here was run, and so was every Python, Clojure and Lua program, with the output each one actually printed. Rebol isn't installed here, so its side is written from its documentation and marked. Back to Sprout 3

SproutPythonRebolClojureLua
Math orderleft to right, no precedenceprecedence rulesleft to rightprefix: (+ 1 2)precedence rules
Functionscells: [n | n * 2]def, lambdafuncfn, defnfunction
Controllibrary cells, not syntaxkeywordsfunctionsspecial forms and macroskeywords
Changing datanever in placein placein placenever in placein place
Literalsdates, times, money, pairs, urls, emails, coloursnumbers and textdates, money, pairs, urls and morekeywords, sets, regexesnumbers and text
Parsingparse with rules as valuesreparseregexespatterns
Code as dataquote, eval, codeast moduleblockslists and macrosstrings and load
Coroutinesscript, a value you can rewindgeneratorsnonenone built incoroutines
Speed on number loopsfused loops, SIMD and WebGPU kernelsinterpreted; NumPy for arraysinterpretedthe JVM, after start-upa fast interpreter; LuaJIT
Where it still leadsgames and simulations in a browser, live editing, rewindlibraries for everythingblocks need no quote; late bindingmacros, the JVM, threadsa tiny embeddable C core

Speed

The same work on one machine, best of several runs. Sprout ran in Node; Clojure's time is after the JVM has warmed up, which takes about a second and a half. A dot means it wasn't measured.

workSproutPython 3.13Clojure 1.12Lua 5.4
A million Monte Carlo trials (pi)19 ms200 msยท72 ms
Counting a million numbers4.3 ms36 ms14 ms13 ms

Sprout and Python

Python is the language most people learn first. Every pair was run in Sprout 3 and Python 3.13, and the output under each one is what it actually printed.

Printing

In Sprout the message comes after the value: "hello, world" print sends print to the text. Every line reads the same way, from the thing to what happens to it.

Sprout
"hello, world" print
prints
hello, world
Python
print("hello, world")
prints
hello, world

Names for values

A colon gives a value a name. Names can have hyphens in them, like star-count, because minus always has spaces round it.

Sprout
price : 12
count : 3
price * count print
prints
36
Python
price = 12
count = 3
print(price * count)
prints
36

Left to right, always

Sprout has no precedence table. Math runs strictly left to right, so 2 + 3 * 4 is 20. Use brackets when you want something done first. There is nothing to remember.

Sprout
2 + 3 * 4 print
2 + (3 * 4) print
prints
20
14
Python
print((2 + 3) * 4)
print(2 + 3 * 4)
prints
20
14

Functions are cells

A function is a cell: inputs, a bar, then the body. The last value in the body is the answer, so there is no return. To call it, write the value after its name.

Sprout
double : [n | n * 2]
double 21 print
prints
42
Python
def double(n):
    return n * 2

print(double(21))
prints
42

Several inputs, and defaults

Every call takes one value. Several inputs go in as a list, in order, or as a record, by name. A default comes after a colon, the same way a name gets a value.

Sprout
area : [w h : 1 | w * h]
area [3, 4] print
area [5] print
area [h : 2, w : 6] print
prints
12
5
12
Python
def area(w, h=1):
    return w * h

print(area(3, 4))
print(area(5))
print(area(h=2, w=6))
prints
12
5
12

Choosing

There is no if keyword. A true or false value takes a cell to run when true, and else (an ordinary library cell) takes the other one. The whole thing is a value, like Python's conditional expression.

Sprout
size : [n | n > 100 ["big"] else ["small"]]
size 250 print
size 7 print
prints
big
small
Python
def size(n):
    return "big" if n > 100 else "small"

print(size(250))
print(size(7))
prints
big
small

Lists

collect, keep and fold are methods on the list, so a chain of them reads left to right. Python spreads the same work over comprehensions and built-in functions.

Sprout
xs : [3, 1, 4, 1, 5, 9]
xs collect [n | n * 2] print
xs keep [n | n > 2] print
xs fold [0, [total n | total + n]] print
xs sort print
prints
[6, 2, 8, 2, 10, 18]
[3, 4, 5, 9]
23
[1, 1, 3, 4, 5, 9]
Python
xs = [3, 1, 4, 1, 5, 9]
print([n * 2 for n in xs])
print([n for n in xs if n > 2])
print(sum(xs))
print(sorted(xs))
prints
[6, 2, 8, 2, 10, 18]
[3, 4, 5, 9]
23
[1, 1, 3, 4, 5, 9]

Records, never changed in place

A record is a list of named fields. with makes a new record with some fields changed; the old one is never touched. Nothing in Sprout changes in place, which is why a game's state can be saved, rewound or compared at any time.

Sprout
point : [x : 1, y : 2]
point x print
moved : point with [x : 5]
moved print
point print
prints
1
[x : 5, y : 2]
[x : 1, y : 2]
Python
point = {"x": 1, "y": 2}
print(point["x"])
moved = {**point, "x": 5}
print(moved)
print(point)
prints
1
{'x': 5, 'y': 2}
{'x': 1, 'y': 2}

Text with values in it

Square brackets inside text hold a value, the same as Python's f-strings with braces. Any expression works inside them.

Sprout
name : "Ada"
"hello, [name]! you have [3 * 4] messages" print
prints
hello, Ada! you have 12 messages
Python
name = "Ada"
print(f"hello, {name}! you have {3 * 4} messages")
prints
hello, Ada! you have 12 messages

A field that may not be there

Asking for a field that isn't there is a quiet miss, not a crash, and else catches it. Python needs .get or a try for the same thing.

Sprout
user : [name : "Ada"]
user nickname else "none" print
prints
none
Python
user = {"name": "Ada"}
print(user.get("nickname", "none"))
prints
none

Matching

match is a library cell, not syntax: a value and a flat list of pattern and answer pairs. any matches anything.

Sprout
answer : [key | match [key, ["tap", "tapped", "drag", "dragged", any, "other"]]]
answer "tap" print
answer "swipe" print
prints
tapped
other
Python
def answer(key):
    match key:
        case "tap": return "tapped"
        case "drag": return "dragged"
        case _: return "other"

print(answer("tap"))
print(answer("swipe"))
prints
tapped
other

Chains of steps

Because methods go after the value, a pipeline reads in the order it runs. Python's comprehension puts the result first and the source in the middle.

Sprout
people : [[name : "Ada", age : 36], [name : "Alan", age : 41], [name : "Grace", age : 85]]
people keep [p | p age > 40] collect [p | p name] print
prints
[Alan, Grace]
Python
people = [{"name": "Ada", "age": 36}, {"name": "Alan", "age": 41}, {"name": "Grace", "age": 85}]
print([p["name"] for p in people if p["age"] > 40])
prints
['Alan', 'Grace']

FizzBuzz

cond takes pairs of test and answer and gives the first answer whose test is true. Lists in Sprout count from 1, so range 15 is 1 to 15.

Sprout
range 15 collect [n | cond [n % 15 = 0, "FizzBuzz", n % 3 = 0, "Fizz", n % 5 = 0, "Buzz", any, n]] print
prints
[1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz]
Python
print(["FizzBuzz" if n % 15 == 0 else "Fizz" if n % 3 == 0 else "Buzz" if n % 5 == 0 else n
       for n in range(1, 16)])
prints
[1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz']

Recursion

A cell can call itself by name. The brackets round n - 1 matter: without them, left to right would read fib n - 1 as (fib n) - 1.

Sprout
fib : [n | n < 2 [n] else [fib (n - 1) + (fib (n - 2))]]
fib 20 print
prints
6765
Python
def fib(n):
    return n if n < 2 else fib(n - 1) + fib(n - 2)

print(fib(20))
prints
6765

A million random trials

This is where the two part ways. noise [n, 1] is a seeded hash, not a random number generator, so run n always draws the same numbers and the answer is the same every time. Because hit is one pure cell, spork compiles it ahead into a kernel of number math and runs it on WebAssembly SIMD or the GPU. In this test, Sprout took 19 ms in Node against 200 ms for the plain CPython loop. NumPy would close most of that gap, at the cost of rewriting the loop as array operations.

Sprout
-- estimate pi: the share of random points in the square that land inside the circle
hit : [n | x : noise [n, 1], y : noise [n, 2], x * x + (y * y) < 1 [1] else [0]]
range 1000000 spork hit fold [0, [total h | total + h]] * 4 / 1000000 print
prints
3.141792
Python
import random

hits = sum(1 for _ in range(1_000_000)
           if random.random() ** 2 + random.random() ** 2 < 1)
print(hits * 4 / 1_000_000)
prints
3.137976

Sprout and Rebol

Rebol showed that a language could be tiny, read left to right, write dates and money as they are, and parse anything with a dialect. Sprout takes all of that. Every Sprout side here was run, and its output is real. Rebol isn't installed on this machine, so the Rebol side is written from Rebol 3's documentation and wasn't run.

Values written as they are

Rebol's best idea: a date, an amount of money or a size is written as it is, and knows its own math. Sprout writes dates the ISO way, 2026-11-20, and keeps money in whole cents.

Sprout
2026-11-20 + 30 print
$19.99 * 3 print
640x480 / 2 print
9:30 + 0:45 print
prints
2026-12-20
$59.97
320x240
10:15
Rebol
print 20-Nov-2026 + 30
print $19.99 * 3
print 640x480 / 2
print 9:30 + 0:45
Rebol isn't installed here, so this side wasn't run.

Left to right, like Rebol

Rebol and Sprout agree: math runs strictly left to right, so this is 20 in both.

Sprout
2 + 3 * 4 print
prints
20
Rebol
print 2 + 3 * 4
Rebol isn't installed here, so this side wasn't run.

Functions

Rebol's func takes a block of inputs and a block of code. A Sprout cell is both in one pair of brackets.

Sprout
twice : [n | n * 2]
twice 21 print
prints
42
Rebol
twice: func [n] [n * 2]
print twice 21
Rebol isn't installed here, so this side wasn't run.

Parsing text

Rebol copies each piece into a variable. Sprout keeps them with as and gives back a record, so nothing outside the rule changes.

Sprout
"2026-11-20" parse [repeat [4, digit] as "year", "-", repeat [2, digit] as "month", "-", repeat [2, digit] as "day"] print
prints
[year : 2026, month : 11, day : 20]
Rebol
digit: charset "0123456789"
parse "2026-11-20" [copy year 4 digit "-" copy month 2 digit "-" copy day 2 digit]
print [year month day]
Rebol isn't installed here, so this side wasn't run.

Finding every match

Rebol collects matches with an action in parens. Sprout has find-all.

Sprout
"call 555-1234 or 555-9876 today" find-all [repeat [3, digit], "-", repeat [4, digit]] print
prints
[555-1234, 555-9876]
Rebol
digit: charset "0123456789"
found: copy []
parse "call 555-1234 or 555-9876 today" [
  some [copy number [3 digit "-" 4 digit] (append found number) | skip]
]
probe found
Rebol isn't installed here, so this side wasn't run.

A grammar

Rebol words are looked up when the rule runs, so rules can refer to each other in any order. Sprout names are bound before use (decision 25), so the grammar is one cell that names itself, with its pieces as fields.

Sprout
expr : [
  factor : one-of [some digit, ["(", expr, ")"]]
  term : [factor, maybe-some [one-of "*/", factor]]
  term, maybe-some [one-of "+-", term]
]
["2*(3+4)", "2*(3+4", "1+2*3-4/5"] collect [t | t parse expr] print
prints
[true, false, true]
Rebol
digit: charset "0123456789"
expr: [term any [["+" | "-"] term]]
term: [factor any [["*" | "/"] factor]]
factor: [some digit | "(" expr ")"]
probe collect [foreach t ["2*(3+4)" "2*(3+4" "1+2*3-4/5"] [keep parse t expr]]
Rebol isn't installed here, so this side wasn't run.

A dialect

Rebol's is shorter: a block is already flat data. Sprout's quoted code keeps its phrases, so each command is checked as a whole with into.

Sprout
turtle : some one-of [into ['move, a-number], into ['turn, a-number]]
quote [move 10, turn 90, move 5] parse turtle print
prints
true
Rebol
turtle: [some ['move integer! | 'turn integer!]]
print parse [move 10 turn 90 move 5] turtle
Rebol isn't installed here, so this side wasn't run.

Running a dialect

Rebol runs code in parens as the rule matches, and changes variables as it goes. Sprout folds over the program and gives back the new state, so nothing changes underneath.

Sprout
walk : [state [command, amount] |
  match [command, ['move, state with [x : state x + amount], 'turn, state with [heading : state heading + amount], any, state]]
]
quote [move 10, turn 90, move 5] fold [[x : 0, heading : 0], walk] print
prints
[x : 15, heading : 90]
Rebol
x: 0 heading: 0
parse [move 10 turn 90 move 5] [
  some ['move set n integer! (x: x + n) | 'turn set n integer! (heading: heading + n)]
]
print [x heading]
Rebol isn't installed here, so this side wasn't run.

Code is data

Both treat code as data. Rebol blocks are data until you do them; Sprout needs quote, because its brackets are cells. Both can get a function's body back.

Sprout
program : quote [1 + 2, 3 * 4]
program print
eval program print
twice : [n | n * 2]
twice code print
prints
[1 + 2, 3 * 4]
12
[n | n * 2]
Rebol
program: [1 + 2 3 * 4]
probe program
print do program
twice: func [n] [n * 2]
probe body-of :twice
Rebol isn't installed here, so this side wasn't run.

Records that don't change underneath you

Rebol makes a new object from an old one too, but any object can also be changed in place, for everyone who holds it. A Sprout record never changes, so a game can rewind.

Sprout
point : [x : 1, y : 2]
moved : point with [x : 5]
moved print
point print
prints
[x : 5, y : 2]
[x : 1, y : 2]
Rebol
point: make object! [x: 1 y: 2]
moved: make point [x: 5]
probe moved
point/x: 5    ; and an object can also be changed in place, for everyone holding it
probe point
Rebol isn't installed here, so this side wasn't run.

Coroutines

Rebol has no coroutines. Sprout's script yields values and stays a value (decision 104).

Sprout
squares : script [| go : [n | yield (n * n), go (n + 1)], go 1]
squares take 5 print
prints
[1, 4, 9, 16, 25]
Rebol
; Rebol has no coroutines: a generator keeps its place in a variable
n: 0
next-square: does [n: n + 1 n * n]
probe collect [loop 5 [keep next-square]]
Rebol isn't installed here, so this side wasn't run.

Unpacking

Rebol reads parts by path, size/x. Sprout can also unpack a pair or a date into names at once (decision 101).

Sprout
[w, h] : 640x480
w * h print
[y, m, d] : 2026-11-20
"[d]/[m]/[y]" print
prints
307200
20/11/2026
Rebol
size: 640x480
print size/x * size/y
day: 20-Nov-2026
print rejoin [day/day "/" day/month "/" day/year]
Rebol isn't installed here, so this side wasn't run.

Sprout and Clojure

Clojure made immutable data and a rich sequence library feel normal. Here is what it is known for, next to the same work in Sprout. Every pair was run in Sprout 3 and in Clojure 1.12, and the output under each one is what it actually printed. The two print collections differently; the values are the same.

A pipeline of steps

Clojure needs the ->> macro to write steps in the order they run. In Sprout every method already reads left to right, so a pipeline is just a line.

Sprout
1 to 10 keep [n | n even] collect [n | n * n] sum print
prints
220
Clojure
(println (->> (range 1 11) (filter even?) (map #(* % %)) (reduce +)))
prints
220

Counting

The same words, the same counts. Sprout prints a record, Clojure a map.

Sprout
"mississippi" chars frequencies print
prints
[m : 1, i : 4, s : 4, p : 2]
Clojure
(println (frequencies "mississippi"))
prints
{m 1, i 4, s 4, p 2}

Grouping

group-by in both. Sprout's keys are the text of each value, since a record's field names are words.

Sprout
people : [[name : "Ada", age : 36], [name : "Alan", age : 41], [name : "Grace", age : 85]]
people group-by [p | p age > 40] print
prints
[false : [[name : Ada, age : 36]], true : [[name : Alan, age : 41], [name : Grace, age : 85]]]
Clojure
(def people [{:name "Ada" :age 36} {:name "Alan" :age 41} {:name "Grace" :age 85}])
(println (group-by #(> (:age %) 40) people))
prints
{false [{:name Ada, :age 36}], true [{:name Alan, :age 41} {:name Grace, :age 85}]}

Changing something deep inside

Both give a new game and leave the old one as it was. Clojure's keywords make the path shorter; Sprout's path is plain text.

Sprout
game : [player : [name : "Ada", score : 10]]
game update-in [["player", "score"], [s | s + 5]] print
game print
prints
[player : [name : Ada, score : 15]]
[player : [name : Ada, score : 10]]
Clojure
(def game {:player {:name "Ada" :score 10}})
(println (update-in game [:player :score] + 5))
(println game)
prints
{:player {:name Ada, :score 15}}
{:player {:name Ada, :score 10}}

Unpacking

Clojure's destructuring, in Sprout's square brackets (decision 101). One pattern unpacks a record by name or a list by position, and ..rest is Clojure's &.

Sprout
greet : [[name, age] | "[name] is [age]"]
greet [name : "Ada", age : 36] print
[first, ..rest] : [1, 2, 3, 4]
rest print
prints
Ada is 36
[2, 3, 4]
Clojure
(defn greet [{:keys [name age]}] (str name " is " age))
(println (greet {:name "Ada" :age 36}))
(let [[first & rest] [1 2 3 4]] (println rest))
prints
Ada is 36
(2 3 4)

Endless lists

Endless lists in both, worked out only as far as they are read. The Fibonacci line unpacks each pair as it goes.

Sprout
iterate [1, [n | n + 1]] keep [n | n % 7 = 0] take 5 print
iterate [[0, 1], [[a, b] | [b, a + b]]] collect [[a, b] | a] take 10 print
prints
[7, 14, 21, 28, 35]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Clojure
(println (take 5 (filter #(zero? (mod % 7)) (iterate inc 1))))
(println (take 10 (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))))
prints
(7 14 21 28 35)
(0 1 1 2 3 5 8 13 21 34)

Slicing a list up

Clojure's sequence words have Sprout names: partition, scan for reductions, zip for map vector.

Sprout
1 to 10 partition 3 print
[3, 1, 4, 1, 5] scan [0, [t n | t + n]] print
[1, 2, 3] zip ["a", "b", "c"] print
prints
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[0, 3, 4, 8, 9, 14]
[[1, a], [2, b], [3, c]]
Clojure
(println (partition 3 (range 1 11)))
(println (reductions + 0 [3 1 4 1 5]))
(println (map vector [1 2 3] ["a" "b" "c"]))
prints
((1 2 3) (4 5 6) (7 8 9))
(0 3 4 8 9 14)
([1 a] [2 b] [3 c])

Code is data

Both can hold code as data and run it. A Sprout cell also keeps its own code, so twice code gives it back; a compiled Clojure function is an object, and its source lives only in the file.

Sprout
program : quote [1 + 2, 3 * 4]
program print
eval program print
twice : [n | n * 2]
twice code print
prints
[1 + 2, 3 * 4]
12
[n | n * 2]
Clojure
(def program '(do (+ 1 2) (* 3 4)))
(println program)
(println (eval program))
(defn twice [n] (* n 2))
;; a function keeps no code of its own; only the REPL can find its source file
(println twice)
prints
(do (+ 1 2) (* 3 4))
12
#object[user$twice 0x22ee2d0 user$twice@22ee2d0]

A little language

The same little turtle language, as quoted data walked by a fold. Sprout's 'move and Clojure's 'move are both symbols you can compare.

Sprout
turtle : [state [command, amount] |
  match [command, ['move, state with [x : state x + amount], 'turn, state with [heading : state heading + amount], any, state]]
]
quote [move 10, turn 90, move 5] fold [[x : 0, heading : 0], turtle] print
prints
[x : 15, heading : 90]
Clojure
(defn turtle [state [command amount]]
  (case command
    move (update state :x + amount)
    turn (update state :heading + amount)
    state))
(println (reduce turtle {:x 0 :heading 0} '[[move 10] [turn 90] [move 5]]))
prints
{:x 15, :heading 90}

Dates

Clojure borrows Java's dates. Sprout writes a date as it is and does its math directly (decision 100).

Sprout
2026-11-20 + 30 print
2026-11-20 weekday print
prints
2026-12-20
Friday
Clojure
(def day (java.time.LocalDate/parse "2026-11-20"))
(println (str (.plusDays day 30)))
(println (str (.getDayOfWeek day)))
prints
2026-12-20
FRIDAY

Counting a million

Counting the multiples of three below a million. Sprout took 4.3 ms on this machine. Clojure took 14 ms once the JVM had warmed up, after about a second and a half to start. A transducer or a loop with primitive math would make Clojure faster.

Sprout
range 1000000 keep [n | n % 3 = 0] length print
prints
333333
Clojure
(defn run [] (count (filter #(zero? (mod % 3)) (range 1 1000001))))
(println (run))
prints
333333

Sprout and Lua

Lua is small, fast and everywhere games are scripted. Here is what it is known for, next to the same work in Sprout. Every pair was run in Sprout 3 and in Lua 5.4, and the output under each one is what it actually printed. Where they differ, the difference is the point.

One structure for records and lists

Both languages have one structure for everything. A Sprout cell holds named fields and numbered parts, as a Lua table does, and lists count from 1 in both.

Sprout
hero : [name : "Ada", items : ["map", "lamp", "rope"]]
hero name print
hero items @ 2 print
hero items length print
prints
Ada
lamp
3
Lua
local hero = {name = "Ada", items = {"map", "lamp", "rope"}}
print(hero.name)
print(hero.items[2])
print(#hero.items)
prints
Ada
lamp
3

The string library

Lua's string library is short and sharp. Sprout's words are named for what they do, so trimming and splitting don't need a pattern. Both count positions from 1, and negative ones from the end.

Sprout
line : "  Sprout, Lua, Rebol  "
line trim print
line trim split ", " join " | " print
"ab" repeat 3 print
"hello" slice [2, -2] print
"hello" upper print
prints
Sprout, Lua, Rebol
Sprout | Lua | Rebol
ababab
ell
HELLO
Lua
local line = "  Sprout, Lua, Rebol  "
local trimmed = line:match("^%s*(.-)%s*$")
print(trimmed)
local parts = {}
for part in trimmed:gmatch("[^,]+") do parts[#parts + 1] = part:match("^%s*(.-)%s*$") end
print(table.concat(parts, " | "))
print(("ab"):rep(3))
print(("hello"):sub(2, -2))
print(("hello"):upper())
prints
Sprout, Lua, Rebol
Sprout | Lua | Rebol
ababab
ell
HELLO

Finding things in text

Lua patterns are a tiny language inside strings: %d for a digit, %- for a dash. Sprout's rules are ordinary values (decision 103), so they can be named, put in lists and built by other code.

Sprout
text : "call 555-1234 or 555-9876 today"
text find-all [repeat [3, digit], "-", repeat [4, digit]] join ", " print
prints
555-1234, 555-9876
Lua
local text = "call 555-1234 or 555-9876 today"
local found = {}
for number in text:gmatch("%d%d%d%-%d%d%d%d") do found[#found + 1] = number end
print(table.concat(found, ", "))
prints
555-1234, 555-9876

Replacing with a function

Both replace each match with what a function makes of it. Lua's gsub also gives back a count, which is why its call needs the extra brackets.

Sprout
"3 apples and 12 pears" replace-all [some digit, [n | n number * 2]] print
prints
6 apples and 24 pears
Lua
print((("3 apples and 12 pears"):gsub("%d+", function(n) return tonumber(n) * 2 end)))
prints
6 apples and 24 pears

A grammar, not just a pattern

Lua patterns can't say "this or that", and can't nest. So nested brackets mean writing a parser by hand. A Sprout rule can hold itself, so the grammar is four lines and reads like a grammar.

Sprout
expr : [
  factor : one-of [some digit, ["(", expr, ")"]]
  term : [factor, maybe-some [one-of "*/", factor]]
  term, maybe-some [one-of "+-", term]
]
["2*(3+4)", "2*(3+4", "1+2*3-4/5"] collect [t | t parse expr] print
prints
[true, false, true]
Lua
-- Lua patterns have no alternation and no recursion, so a grammar is a hand-written parser
local function parse(s)
  local pos = 1
  local expr
  local function factor()
    if s:sub(pos, pos) == "(" then
      pos = pos + 1
      if not expr() or s:sub(pos, pos) ~= ")" then return false end
      pos = pos + 1
      return true
    end
    local from, to = s:find("^%d+", pos)
    if not from then return false end
    pos = to + 1
    return true
  end
  local function term()
    if not factor() then return false end
    while s:sub(pos, pos):match("[*/]") do pos = pos + 1; if not factor() then return false end end
    return true
  end
  expr = function()
    if not term() then return false end
    while s:sub(pos, pos):match("[+-]") do pos = pos + 1; if not term() then return false end end
    return true
  end
  return expr() and pos == #s + 1
end
local results = {}
for _, t in ipairs({"2*(3+4)", "2*(3+4", "1+2*3-4/5"}) do results[#results + 1] = tostring(parse(t)) end
print("[" .. table.concat(results, ", ") .. "]")
prints
[true, false, true]

Coroutines

A generator in both. Sprout's script yields the same way a Lua coroutine does (decision 104).

Sprout
squares : script [| go : [n | yield (n * n), go (n + 1)], go 1]
squares take 5 join ", " print
prints
1, 4, 9, 16, 25
Lua
local squares = coroutine.wrap(function()
  local n = 1
  while true do coroutine.yield(n * n); n = n + 1 end
end)
local out = {}
for i = 1, 5 do out[i] = squares() end
print(table.concat(out, ", "))
prints
1, 4, 9, 16, 25

A coroutine you can go back to

This is where they part. A Lua coroutine is one live object: resuming it moves it on for everyone. A Sprout script is a value: resuming gives a new one and leaves the old one as it was. That is why a game can keep a script in its state and still rewind time.

Sprout
counter : script [| yield 1, yield 2, yield 3]
first : counter next
second : first next
second value print
-- first hasn't changed, so it can be resumed again
first next value print
prints
2
2
Lua
local counter = coroutine.create(function()
  coroutine.yield(1); coroutine.yield(2); coroutine.yield(3)
end)
coroutine.resume(counter)
local _, second = coroutine.resume(counter)
print(second)
-- there is only one counter, and it has moved on
local _, again = coroutine.resume(counter)
print(again)
prints
2
3

Your own operators

A Lua metatable gives a table its own +. In Sprout a record has a field named +, and left is the record it was sent to.

Sprout
vector : [
  + : [right | left with [x : left x + (right x), y : left y + (right y)]]
]
sum : (vector with [x : 1, y : 2]) + (vector with [x : 3, y : 4])
"[sum x], [sum y]" print
prints
4, 6
Lua
local Vector = {}
Vector.__index = Vector
function Vector.new(x, y) return setmetatable({x = x, y = y}, Vector) end
Vector.__add = function(a, b) return Vector.new(a.x + b.x, a.y + b.y) end
local sum = Vector.new(1, 2) + Vector.new(3, 4)
print(sum.x .. ", " .. sum.y)
prints
4, 6

Dates

Lua has no dates, only seconds since 1970 and os.date. In Sprout a date is a value with its own math (decision 100).

Sprout
2026-11-20 + 30 print
2026-11-20 weekday print
prints
2026-12-20
Friday
Lua
local t = os.time({year = 2026, month = 11, day = 20, hour = 12}) + 30 * 86400
print(os.date("!%Y-%m-%d", t))
print(os.date("!%A", os.time({year = 2026, month = 11, day = 20, hour = 12})))
prints
2026-12-20
Friday

Money

Lua's numbers are floats, so 0.10 + 0.20 isn't 0.30, and $100 shared three ways loses a cent. Sprout's money is whole cents, and split hands out every one.

Sprout
$0.10 + $0.20 = $0.30 print
$19.99 * 3 print
$100.00 split 3 print
prints
true
$59.97
[$33.34, $33.33, $33.33]
Lua
print(0.10 + 0.20 == 0.30)
print(string.format("$%.2f", 19.99 * 3))
local share = 100 / 3
print(string.format("$%.2f, $%.2f, $%.2f", share, share, share))
prints
false
$59.97
$33.33, $33.33, $33.33

Unpacking

Lua's multiple assignment unpacks values one by one. Sprout's patterns unpack lists, records and pairs, with ..rest for what's left (decision 101).

Sprout
[x, y] : 640x480
x * y print
[first, ..rest] : [1, 2, 3, 4]
rest print
prints
307200
[2, 3, 4]
Lua
local x, y = 640, 480
print(x * y)
local list = {1, 2, 3, 4}
local first, rest = list[1], {table.unpack(list, 2)}
print("[" .. table.concat(rest, ", ") .. "]")
prints
307200
[2, 3, 4]

A million random trials

Both estimate pi from a million random points. On this machine Sprout took 19 ms (Node, WebAssembly SIMD) and Lua 5.4 took 72 ms. Counting a million numbers took Sprout 4.3 ms and Lua 13 ms. LuaJIT, where it runs, would be faster than Lua 5.4; it wasn't measured here. Sprout's draws come from a seeded hash, so its answer is the same on every run.

Sprout
hit : [n | x : noise [n, 1], y : noise [n, 2], x * x + (y * y) < 1 [1] else [0]]
range 1000000 spork hit fold [0, [total h | total + h]] * 4 / 1000000 print
prints
3.141792
Lua
local hits = 0
for i = 1, 1000000 do
  local x, y = math.random(), math.random()
  if x * x + y * y < 1 then hits = hits + 1 end
end
print(hits * 4 / 1000000)
prints
3.14156

Python 3.13, Clojure 1.12 on Java, and Lua 5.4 through lupa, all on one machine. Run the benchmarks to see Sprout's numbers on your own device.