← Sprout

Sprout among the languages

Sprout is a small language for games and simulations, and a bit of a magpie: it took good ideas from older languages and left the rest. Here it stands beside thirteen of them, from BASIC and Smalltalk to Elm, with the same small programs written side by side.

On this page: one plus two times three · at a glance · four small programs · what Sprout took · better choices

What's unusual

Here is most of it in a few lines. The grey lines are the answers, worked out by Sprout itself:

double : [n | n * 2]
point : [x : 3, y : 4]
primes : [2, 3, 5, 7]
primes collect double
-- [4, 6, 10, 14]
point with [x : double 5]
-- [x : 10, y : 4]
point
-- [x : 3, y : 4]
1 + 2 * 3
-- 9

One plus two times three

Every language has to decide what to work out first. Most borrow the rule from school, where times goes before plus. Sprout does what Smalltalk and Rebol do and simply reads from left to right. APL has no rule either, but reads from the right.

Reads1 + 2 * 32 * 3 + 1
Left to rightSprout, Smalltalk, Rebol97
By precedencePython, JavaScript, Lua, Ruby, Haskell, Elm, BASIC, HyperTalk77
Right to leftAPL, which writes × for times78

Clojure and Scratch never meet the question. In Clojure you write the nesting yourself, (+ 1 (* 2 3)), and in Scratch you drop one block inside the other. Sprout's answers were run, and so were Python's, JavaScript's, Ruby's and Lua's; the rest follow from each language's rules.

At a glance

Sprout and thirteen others, oldest first after Sprout. Read across for one language, or down a column to see where Sprout sits.

LanguageDo values change?Order of workA functionA recordLazinessLive coding and rewindWhere it runsTypes
Sprout2026Never: with makes a new oneLeft to right, one send at a time[n | n * 2][x : 1, y : 2], a cellA field is worked out when first read, then kept; endless listsEdit while it runs; every game rewinds and replaysAny browser, phone or desk; NodeDynamic; an unknown message gives false and a note
BASIC1964Yes: LET X = X + 1PrecedenceDEF FND(N) = N * 2None in the classic dialectsEagerType a line, RUN; edit, RUN againIn the ROM of the home computersNumbers, and text in names ending in $
APL1966Arrays are values; a name can take a new oneRight to left, no precedence{⍵×2}Arrays; namespaces in DyalogEagerA live session and workspace; no rewindDyalog, GNU APL; TryAPL in a browserDynamic arrays of numbers or characters
Smalltalk1972Yes: objects change in placeLeft to right; unary messages first, keywords last[:n | n * 2]An object of a classEager; a block waits to be sent valueThe whole system is live, even the debugger; no rewindIts own image and VM: Pharo, SqueakDynamic; doesNotUnderstand:
HyperTalk1987Yes: put changes a containerPrecedencefunction double n … end doubleA card with fieldsEagerAlways live: edit a button's script, then click itHyperCard on the classic Mac; LiveCode todayEverything is text
Haskell1990Never; effects go through IOPrecedence, set per operator\n -> n * 2P { x = 1, y = 2 }Lazy throughout, each value worked out onceGHCi and :reload; no rewindCompiled to native codeStatic, inferred, with type classes
Python1991Yes: lists, dicts and objects change in placePrecedencelambda n: n * 2A dict, or a dataclassEager; generators are lazyA REPL; no rewindDesktops and servers; browsers through PyodideDynamic, with optional hints
Lua1993Yes: tables change in placePrecedencefunction(n) return n * 2 endA table, {x = 1, y = 2}Eager; coroutinesOften reloaded inside a running game; no rewindAnywhere C runs, inside games and appsDynamic
JavaScript1995Yes: const only stops a name being reusedPrecedencen => n * 2An object, {x: 1, y: 2}Eager; generators are lazyHot reload in tools; Redux's tools step back in timeEvery browser; Node, Deno, BunDynamic, with quiet conversions; TypeScript adds types
Ruby1995Yes, until you freezePrecedence{ |n| n * 2 }, a blockA hash, {x: 1, y: 2}, or DataEager; .lazy enumeratorsirb; classes reopen while running; no rewindServers and scriptsDynamic, duck typed
Rebol1997Yes: series and objects change in placeLeft to rightfunc [n] [n * 2]make object! [x: 1 y: 2]A block is data until you do itA console; no rewindA tiny interpreter; Red carries it onDynamic, with dates, money, pairs and urls
Clojure2007Never; atoms hold what does changePrefix: you write the nesting(fn [n] (* n 2))A map, {:x 1 :y 2}Lazy sequencesA REPL into the running programThe JVM; browsers through ClojureScriptDynamic
Scratch2007Yes: “change score by 1”Blocks nest, so their shape is the orderA block of your own, from My BlocksNone: variables and listsEagerAlways live: click a block while it runsBrowsers and the Scratch appNumbers and text, converted as needed
Elm2012NeverPrecedence\n -> n * 2{ x = 1, y = 2 }, its fields fixed by its typeEagerA debugger that steps back through every messageBrowsers, compiled to JavaScriptStatic, inferred; no runtime exceptions in practice

The table scrolls sideways; the names stay put.

Four small programs

Four small jobs, in Sprout and in four languages many people already know. Every one was run. Beside each is the answer Sprout gave, or what the others printed.

Add up the squares of the odd numbers

Sprout
xs : [3, 8, 5, 2, 7]
xs keep [n | n odd] collect [n | n * n] sum
answer
83
Python
xs = [3, 8, 5, 2, 7]
print(sum(n * n for n in xs if n % 2 == 1))
prints
83
JavaScript
const xs = [3, 8, 5, 2, 7];
console.log(xs.filter(n => n % 2 === 1)
  .map(n => n * n).reduce((a, b) => a + b, 0));
prints
83
Ruby
xs = [3, 8, 5, 2, 7]
puts xs.select(&:odd?).sum { |n| n * n }
prints
83
Lua
local xs = {3, 8, 5, 2, 7}
local total = 0
for _, n in ipairs(xs) do
  if n % 2 == 1 then total = total + n * n end
end
print(total)
prints
83

Sprout, Ruby and JavaScript read in the order the work happens: keep the odd ones, square them, add them up. Python's generator starts with the square and ends with the test, and Lua writes the loop out with a running total. On a long list of numbers Sprout runs its whole chain as one loop, with no lists made in between.

Count each word in a sentence

Sprout
"the cat sat on the mat" words tally
answer
[the : 2, cat : 1, sat : 1, on : 1, mat : 1]
Python
from collections import Counter
print(Counter("the cat sat on the mat".split()))
prints
Counter({'the': 2, 'cat': 1, 'sat': 1, 'on': 1, 'mat': 1})
JavaScript
const counts = {};
for (const w of "the cat sat on the mat".split(" "))
  counts[w] = (counts[w] ?? 0) + 1;
console.log(counts);
prints
{ the: 2, cat: 1, sat: 1, on: 1, mat: 1 }
Ruby
p "the cat sat on the mat".split.tally
prints
{"the"=>2, "cat"=>1, "sat"=>1, "on"=>1, "mat"=>1}
Lua
local counts = {}
for w in ("the cat sat on the mat"):gmatch("%S+") do
  counts[w] = (counts[w] or 0) + 1
end
print(counts.the, counts.cat, counts.mat)
prints
2	1	1

Ruby calls it tally, and so does Sprout, which took the word from Ruby; Clojure's name for it, frequencies, works too. Python keeps a Counter in its library. JavaScript and Lua count by hand, changing a table as they go, and a Lua table has no order and no way to print itself, so Lua prints three of the counts.

Add a field to a record

Sprout
pip : [name : "Pip", leaves : 2]
tall : pip with [height : 12]
[pip, tall]
answer
[[name : Pip, leaves : 2], [name : Pip, leaves : 2, height : 12]]
Python
pip = {"name": "Pip", "leaves": 2}
tall = {**pip, "height": 12}
print(pip)
print(tall)
prints
{'name': 'Pip', 'leaves': 2}
{'name': 'Pip', 'leaves': 2, 'height': 12}
JavaScript
const pip = { name: "Pip", leaves: 2 };
const tall = { ...pip, height: 12 };
console.log(pip);
console.log(tall);
prints
{ name: 'Pip', leaves: 2 }
{ name: 'Pip', leaves: 2, height: 12 }
Ruby
pip = { name: "Pip", leaves: 2 }
tall = pip.merge(height: 12)
p pip
p tall
prints
{:name=>"Pip", :leaves=>2}
{:name=>"Pip", :leaves=>2, :height=>12}
Lua
local pip = {name = "Pip", leaves = 2}
local tall = {height = 12}
for k, v in pairs(pip) do tall[k] = v end
print(pip.height, tall.height, tall.name)
prints
nil	12	Pip

All five can make a new record and leave the old one alone. The difference is what else they allow. In Python, JavaScript, Ruby and Lua, anyone holding pip can still change it in place, and everyone else holding it sees the change. In Sprout nobody can, ever, so a value you've seen stays the value you saw. Elm and Haskell make the same promise, though an Elm record keeps the fields its type gave it, so adding one means a new type.

A counter that remembers

A tap counter, kept the way a game keeps its state: an update takes the state and an event and gives back the next state. Each version runs four events and keeps every state along the way.

Sprout
start : [taps : 0]
update : [game event |
  event = "tap" [game with [taps : game taps + 1]] else [game]
]
["tap", "tick", "tap", "tap"] scan [start, update]
answer
[[taps : 0], [taps : 1], [taps : 1], [taps : 2], [taps : 3]]
Python
from itertools import accumulate

def update(game, event):
    if event == "tap":
        return {**game, "taps": game["taps"] + 1}
    return game

events = ["tap", "tick", "tap", "tap"]
print(list(accumulate(events, update, initial={"taps": 0})))
prints
[{'taps': 0}, {'taps': 1}, {'taps': 1}, {'taps': 2}, {'taps': 3}]
JavaScript
const update = (game, event) =>
  event === "tap" ? { ...game, taps: game.taps + 1 } : game;

const history = [{ taps: 0 }];
for (const event of ["tap", "tick", "tap", "tap"])
  history.push(update(history.at(-1), event));
console.log(history);
prints
[ { taps: 0 }, { taps: 1 }, { taps: 1 }, { taps: 2 }, { taps: 3 } ]
Ruby
def update(game, event)
  event == "tap" ? game.merge(taps: game[:taps] + 1) : game
end

history = [{ taps: 0 }]
["tap", "tick", "tap", "tap"].each do |event|
  history << update(history.last, event)
end
p history
prints
[{:taps=>0}, {:taps=>1}, {:taps=>1}, {:taps=>2}, {:taps=>3}]
Lua
local function update(game, event)
  if event == "tap" then return {taps = game.taps + 1} end
  return game
end

local history = {{taps = 0}}
for _, event in ipairs({"tap", "tick", "tap", "tap"}) do
  history[#history + 1] = update(history[#history], event)
end
for _, game in ipairs(history) do io.write(game.taps, " ") end
print()
prints
0 1 1 2 3

Every one of these keeps its history, because each update here gives back a new state. In Python, JavaScript (it's how Redux works), Ruby and Lua that's a habit, and nothing holds you to it: had Python's update added to game["taps"] in place, its list would read 3, 3, 3, 3, 3, every entry the same dict. In Sprout it's the only way an update can be written, so the game loop keeps the list for you, and that list is the rewind. In a real game the events are the ticks, taps and keys, and the random numbers drawn along the way are recorded too, so a replay comes out the same, frame for frame. Elm's update has this shape and makes the same promise.

What Sprout took, and what it left

Seven of these languages lent Sprout something on purpose, and the spec records each loan as a numbered decision. Six more sit close by: they reached some of the same ideas first, or chose the other way, and they help show where Sprout stands. The lines of Sprout below were run; lines of the other languages are written from their documentation.

Borrowed from

Smalltalk 1972

Took the one move everything is made of: send a message to a value, then the next message to the answer, left to right, operators included. Blocks with a bar after their inputs: Smalltalk's [:n | n * 2] is Sprout's [n | n * 2]. A value that doesn't understand a message says so and the program carries on, and now any value can be asked what it understands:

3 responds-to "pow"
-- true
"hi" responds-to "pow"
-- false

Left classes, since a value gets its methods through with; unary messages going before operators, so Sprout's a x + r x is ((a x) + r) x; keyword messages like at: 1 put: 2 and cascades, which would be new grammar and wait as proposals; objects that change.

HyperTalk 1987

Took the chunk words, so text reads the way HyperCard read it, and stack, for an app made of cards that can go next, go by name, find words, put a value into a field and add a card.

"the quick brown fox" word 2
-- quick
"red, green, blue" item 2
-- green

Left the English sentences, as in put word 2 of field "notes" into field "title", which would change Sprout's grammar and wait as a proposal; and values that are all text.

Lua 1993

Took one structure for lists and records, counted from 1, as a Lua table is; .. to join; the string words; coroutines, which became scripts that stay values; and from metatables, the idea that a record can carry its own +.

"lives: " .. 3
-- lives: 3
["map", "lamp", "rope"] @ 1
-- map

Left nil, since Sprout's one empty value is false; tables that change under you; the C interface for living inside other programs. Sprout and Lua, side by side

JavaScript 1995

Took a home. Sprout compiles to JavaScript and runs wherever it runs, on a phone or a desk, with WebAssembly and WebGPU for the heaviest loops, and popular JavaScript libraries (chroma, simplex noise, math.js, date-fns, Fuse, compromise, Tone, Turf and ZzFX) are Sprout modules.

Left this, null and undefined, precedence, objects that change in place, and quiet conversions: JavaScript's "5" * 2 is 10. Sprout's text doesn't know *, so it says so, and you say what you mean:

"5" responds-to "*"
-- false
"5" number * 2
-- 10

Ruby 1995

Took some of Ruby's best-loved words. And from _why, who wrote about Ruby with cartoon foxes, a storybook, A Slightly Soggy Guide to Sprout, and, after his little language Potion, lick, which reads data written as an indented outline.

5 then [n | n * 2]
-- 10
"az" succ
-- ba
1907 digits
-- [1, 9, 0, 7]

Ruby's 1907.digits comes ones first, [7, 0, 9, 1]; Sprout's come in reading order.

Left names ending in ? and ! and method_missing, which wait as proposals; classes; objects that change.

Rebol 1997

Took values written as they are, dates, times, money, pairs, urls and colours, each with its own math; parse, with rules that are ordinary values; reading left to right; code as data.

2026-12-25 - 2026-11-23
-- 32
2026-11-23 weekday
-- Monday
15% * 80
-- 12

Left words looked up late, since a Sprout name is bound before it's used; series that change in place; blocks that need no quote. Sprout and Rebol, side by side

Clojure 2007

Took values that never change, as the normal case; the sequence words, frequencies, group-by, partition and the rest; endless lists, worked out only as far as they're read; unpacking a value into names; update-in.

cycle ["red", "amber", "green"] take 5
-- [red, amber, green, red, amber]

Left Lisp's brackets with the function first, and macros; the JVM; atoms and threads. Sprout and Clojure, side by side

Close by

BASIC 1964

Shares the feeling of a machine that switches on ready to play. BASIC was the language a home computer greeted you with. Sprout's games come in handhelds of their own, and any of them opens in the editor to be looked at and changed.

Left line numbers, GOTO, and variables that any line can change.

APL 1966

Shares no precedence table, one rule for order, and working on a whole list at once:

range 5 collect [n | n * n]
-- [1, 4, 9, 16, 25]
2 * 3 + 1
-- 7

APL writes the first as (⍳5)*2, and its 2×3+1 is 8, since it reads from the right.

Left the symbols, and reading right to left.

Haskell 1990

Shares values that never change, and laziness of the same kind: a field of a Sprout cell is worked out the first time it's read and then kept, which is how Haskell works out everything. Endless lists too; Haskell says take 6 (iterate (*2) 1):

iterate [1, [n | n * 2]] take 6
-- [1, 2, 4, 8, 16, 32]

Left types and type classes, and monads for effects: Sprout queues a game's sounds and other effects, and the host carries them out after update.

Python 1991

Shares an indent that means something: a new line and an indent make a cell.

size :
  w : 360
  h : 480
size h
-- 480

And text with values in it: Python's f"{name}" is Sprout's "[name]".

Left statements and return, since the last value is the answer; precedence; lists and dicts that change in place. Sprout and Python, side by side

Scratch 2007

Shares games first, in the browser, for people starting out, and a program you can change while it runs.

Left the blocks you drag. Sprout is typed, but its editor is made for touch: a key bar, live values beside each line, numbers you drag to change, and history to scrub back through.

Elm 2012

Shares the shape of a program. Elm's init, update and view are Sprout's start, update and draw, and in both, update gives back a new state instead of changing the old one. That's what lets Elm's debugger step back through every message, and every Sprout game rewind.

Left static types, and a compiler that checks every case before anything runs.

When another language is the better choice

Sprout is good at one thing: small games and simulations that run in a browser and can be changed while they run. For most other work, something on this page will serve you better.

And where Sprout is weaker, plainly:

One on one

For four of these languages there's a longer page, with a dozen or so programs side by side, each pair run.