Part IV. Reference · this page as markdown
Index of examples
Every example in the book, page by page, with the section it teaches and the words of the table it uses. Each links to the example itself.
Preface #
- preface-sum (The two ways in; runs):
(+ 2 3),+ - preface-key (The two ways in; runs with a key):
(+ 2 3),+ - preface-bell (How to read the examples; runs):
defobject,say
Forms and values #
- forms-values (Values answer themselves; runs):
(+ 2 3),:k - forms-collections (Values that hold values; runs):
#"…",(+ 2 3),:k,hash-set,{"a" 1 :b 2} - forms-calls (Lists that work something out; runs):
(+ 2 3),*,+,-,max,str - forms-nested (Inside out; runs):
(+ 2 3),*,+,str - forms-type (What kind of value; runs):
(+ 2 3),:k,type,{:k v} - forms-quote (A list as data; runs):
(+ 2 3),list - forms-comment (Notes to yourself; runs):
(+ 2 3),* - forms-unknown (A word that isn't one; is refused)
Names #
- names-let (let; runs):
(+ 2 3),(let [x (atom v)] …),* - names-several (let; runs):
(+ 2 3),(let [x (atom v)] …),*,str - names-outside (Where a name reaches; is refused):
(+ 2 3),(let [x (atom v)] …) - names-taken (Good names; is refused)
- names-unchanged (Values don't change; runs):
(+ 2 3),(assoc m :k v),(let [x (atom v)] …),{:k v} - names-again (Values don't change; runs):
(+ 2 3),(let [x (atom v)] …),+ - names-apart (Taking values apart; runs):
(+ 2 3),(get m :k),(let [x (atom v)] …),:k,nth,str,{"a" 1 :b 2} - names-keys (Reading a key; runs):
(+ 2 3),(get m :k),{:k v} - names-atom (A name that changes, at the top of a plan; runs):
(+ 2 3),(dotimes [i n] …),(let [x (atom v)] …),(swap! x + n) - names-swaps (A name that changes, at the top of a plan; runs):
(+ 2 3),(let [x (atom v)] …),(reset! x v),(swap! x + n),(swap! x conj v),(swap! x not),{:k v}
Text, lists and maps #
- text-basics (Text; runs):
(+ 2 3),count,str,subs - text-words (Text; runs):
(+ 2 3),blank?,ends-with?,includes?,lower,replace-all,starts-with?,trim… - text-split (Text into lists, and back; runs):
(+ 2 3),(join sep l),split,words - text-format (Numbers in text; runs):
(+ 2 3),format,parse-double,parse-long - text-keywords (Keywords and text; runs):
(+ 2 3),:k,name - text-patterns (Patterns; runs):
#"…",(+ 2 3),re-find,re-matches,re-seq - lists-read (Lists; runs):
(+ 2 3),count,empty?,first,last,nth,rest,second - lists-make (Lists; runs):
(+ 2 3),(concat a b),(reverse l),(vec (range a b)),conj,cons,distinct,drop… - maps-read (Maps; runs):
(+ 2 3),(get m :k),:k,contains?,count,get-in,keys,vals… - maps-make (Maps; runs):
(+ 2 3),(assoc m :k v),:k,assoc-in,count,dissoc,inc,merge… - sets (Sets; runs):
(+ 2 3),(reset! x v),conj,contains?,disj,hash-set
Tests and choices #
- choices-tests (Tests; runs):
(+ 2 3),<,=,>=,empty?,even?,nil?,not=… - choices-logic (Tests; runs):
(+ 2 3),<,=,>,and,not,or - choices-truthy (What counts as true; runs):
(+ 2 3),(get m :k),and,or,{:k v} - choices-if (if; runs):
(+ 2 3),(if t … …),(let [x (atom v)] …),=,>,str - choices-when (when; runs):
(+ 2 3),(if t … …),>,str - choices-when-let (when; runs):
(+ 2 3),(if t … …),(let [x (atom v)] …),=,first,not,str - choices-cond (cond; runs):
(+ 2 3),(let [x (atom v)] …),:k,<,=,cond - choices-case (case; runs):
(+ 2 3),(case x 1 "a" "b"),:k,list - choices-threading (Threading; runs):
(+ 2 3),(assoc m :k v),(if t … …),(let [x (atom v)] …),(map f l),:k,count,inc…
Working over lists #
- lists-map (map; runs):
(+ 2 3),(map f l),count,count,inc,upper - lists-map-fn (map; runs):
(+ 2 3),(fn [a b] …),(map f l),*,str - lists-map-two (map; runs):
(+ 2 3),(fn [a b] …),(map f l),str - lists-for (for; runs):
(+ 2 3),(fn [a b] …),(map f l),str - lists-filter (filter and remove; runs):
(+ 2 3),(fn [a b] …),(range a b),(swap! x (fn …)),>,count,count,even?… - lists-keep (filter and remove; runs):
(+ 2 3),(fn [a b] …),(if t … …),*,keep,odd? - lists-reduce (reduce; runs):
(+ 2 3),(fn [a b] …),+,count,count,max,reduce - lists-reduce-map (reduce; runs):
(+ 2 3),(fn [a b] …),count,fnil,inc,reduce,update,{:k v} - lists-ask (Asking about a whole list; runs):
(+ 2 3),(fn [a b] …),(if t … …),=,count,even?,every?,neg?… - lists-sort (Sorting and grouping; runs):
(+ 2 3),>,count,count,frequencies,group-by,max-key,sort… - lists-more (More list words; runs):
(+ 2 3),(fn [a b] …),+,<,apply,count,inc,interpose… - lists-dotimes (Repeating something a number of times; runs):
(+ 2 3),(dotimes [i n] …),(join sep l),(let [x (atom v)] …),(swap! x conj v)
Functions #
- fn-call (fn; runs):
((fn …) x),(+ 2 3),(fn [a b] …),* - fn-map (fn; runs):
(+ 2 3),(fn [a b] …),(map f l),*,filter,starts-with? - fn-short (The short way: #( ); runs):
(+ 2 3),(fn [a b] …),(map f l),*,str - fn-defn (defn; runs):
(+ 2 3),(defn f [a] …),(f a b),(if t … …),(map f l),=,str - fn-let-top (defn; is refused):
(+ 2 3),(f a b),(fn [a b] …),(let [x (atom v)] …),* - fn-makers (Functions that make functions; runs):
((fn …) x),(+ 2 3),+,comp,complement,constantly,count,count… - fn-recursion (A function that calls itself; runs):
(+ 2 3),(defn f [a] …),(f a b),(if t … …),=,cons,dec - fn-forever (A function that calls itself; is refused):
(+ 2 3),(defn f [a] …),(f a b),inc - fn-loop (loop and recur; runs):
(+ 2 3),(if t … …),(loop [i 0] …),+,>,inc,recur - fn-values (A function as a value; runs):
(+ 2 3),(fn [a b] …),(get m :k),(let [x (atom v)] …),(map f l),str,{:k v}
Chance that repeats #
- chance-words (The words; runs):
(+ 2 3),pick-one,rand,rand-int,rand-nth,shuffle - chance-again-1 (Where the chance comes from; runs):
(+ 2 3),rand-int - chance-again-2 (Where the chance comes from; runs):
(+ 2 3),rand-int - chance-die (Chance in a toy; runs):
(defobject name {…}),inc,rand-int,say,str - chance-jar (Chance in a toy; runs):
defobject,say - chance-in-turn (Chance without repeats; runs):
(+ 2 3),(fn [a b] …),(let [x (atom v)] …),(map f l),(range a b),count,mod,nth
Reading your own home #
- home-coins (Your coins; runs):
(+ 2 3),coins - home-house (Your house; runs):
(+ 2 3),(get m :k),(map f l),:k,count,house,keys - home-house-deep (Your house; runs):
(+ 2 3),(get m :k),:k,first,get-in,house - home-storage (What you keep; runs):
(+ 2 3),(get m k),materials,storage - home-time (The time and the sky; runs):
(+ 2 3),(get m :k),sky,weather,world-time - home-greeting (The time and the sky; runs):
(+ 2 3),(= :night (:time (sky))),(if t … …) - home-plan (What a plan is; runs):
(+ 2 3),+,coins,str - home-each (What a plan is; runs):
(+ 2 3),(dotimes [i n] …),*
A first toy #
- bell (The bell; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - bell-better (Better words; runs):
(defobject name {…}),(f a b),(fn [a b] …),(get m :k),(if t … …),(let [x (atom v)] …),:k,=… - bell-who (Who played; runs):
(defobject name {…}),(get m :k),(let [x (atom v)] …),:k,do,inc,put!,say… - bell-two-verbs (More than one verb; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - owl-ask (More than one verb; runs):
defobject,say - bell-lines (Saying more than one line; runs):
defobject,say
A toy that listens #
- parrot (:on-hear; runs):
(defobject name {…}),(if t … …),includes?,lower,say - riddle-stone (Spoken to, or overheard; runs):
(defobject name {…}),(get m :k),(if t … …),includes?,lower,say,{:k v} - parrot-match (Matching words; runs):
(defobject name {…}),(if t … …),(let [x (atom v)] …),first,match,say,str - mirror (Turning words round; runs):
(defobject name {…}),(get m :k),(if t … …),reflect,say,str - doorbell (Knowing who spoke; runs):
(defobject name {…}),(get m :k),(if t … …),=,say,str
Keeping time #
- sundial (:on-tick, at dawn; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - greeter-time (The time of day; runs):
(case x 1 "a" "b"),(defobject name {…}),(get m :k),:k,say,sky - mood-stone (Your colour; runs):
(case x 1 "a" "b"),(defobject name {…}),(get m :k),(if t … …),:k,colour,my-colour,say… - welcome-sign (:on-visit, on the Commons; runs):
(defobject name {…}),say,str
A toy with a memory #
- guest-log (A guest log; runs):
(defobject name {…}),(get m :k),(join sep l),:k,conj,put!,say,str… - friend-counter (A count for each friend; runs):
(defobject name {…}),(get m :k),(get m k),(if t … …),(let [x (atom v)] …),:k,=,count… - wish-jar (A wish jar; runs):
(defobject name {…}),(get m :k),(if t … …),(join sep l),(let [x (atom v)] …),:k,conj,do… - hoarder (What a memory can hold; runs):
(defobject name {…}),(dotimes [i n] …),(join sep l),:k,put!,{:k v}
A small game #
- game-state (Each player's own game; a fragment):
(+ 2 3),{"a" 1 :b 2},{:k v} - refuse-example (Saying no; a fragment)
- stone-pile (The whole toy; runs):
#"…",(defobject name {…}),(f a b),(fn [a b] …),(get m :k),(get m k),(if t … …),(join sep l)…
Pictures and dances #
- flag (A design; runs):
design - heart (A design; runs):
design - stairs (A design worked out; runs):
(defn f [a] …),(f a b),(fn [a b] …),(if t … …),(join sep l),(map f l),(mapv (fn [x] …) l),(range a b)… - stairs-and-answer (A design worked out; is refused):
(+ 2 3),(defn f [a] …),(f a b),(fn [a b] …),(if t … …),(join sep l),(map f l),(mapv (fn [x] …) l)… - frame (A design worked out; runs):
(defn f [a] …),(f a b),(fn [a b] …),(if t … …),(join sep l),(map f l),(mapv (fn [x] …) l),(range a b)… - porch-step (A dance; runs):
defdance - garden-waltz (A dance; runs):
defdance - own-things (Your own things, by name; runs):
(+ 2 3),(get m :k),(own? :toy "name") - porch-again (Your own things, by name; runs):
(vec (concat a b)),defdance
The house as a form #
- house-roof-read (Read it first; runs):
(+ 2 3),(get m :k),first,house - house-roof (The roof; runs):
(+ 2 3),(get m :k),first,house,roof - house-finish (Floors, window boxes and paint; runs):
floor,paint,window-box - house-more (A porch, a chimney, a storey; runs):
build-up,chimney,porch - house-room (A porch, a chimney, a storey; runs):
room - house-place (Things in their places; runs):
defobject,say - house-move (Things in their places; runs):
move - house-place-twice (Things in their places; is refused):
place - house-all-or-nothing (When something won't do; is refused):
hang-lights,roof - house-still (When something won't do; runs):
(+ 2 3),(get m :k),first,house - house-worked-out (A value worked out; runs):
(+ 2 3),(get m :k),(if t … …),(let [x (atom v)] …),:k,=,first,house… - house-worked-out-plain (A value worked out; is refused):
(let [x (atom v)] …) - house-worked-out-bad (A value worked out; is refused):
(let [x (atom v)] …),*,roof - house-shape (The whole shape; runs):
(+ 2 3),(get m :k),(map f l),:k,house,house
Living with others #
- walls-eval (The walls; is refused)
- walls-like (The walls; is refused):
paint - walls-toy (What a toy can do; is refused)
- open-bell (Open toys; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - closed-chime (Open toys; runs):
defobject,say - mira-kettle (Open toys; runs with a key):
(defobject name {…}),(get m :k),:k,inc,place,put!,say,str… - mira-after (Making one after another; runs with a key)
- after-chat (Making one after another; is refused)
- manners (Manners in what a toy says; runs):
defobject,say
Limits, errors and refusals #
- err-form (Before it runs; is refused)
- err-ratio (Before it runs; is refused)
- err-field (Before it runs; is refused)
- err-times (Before it runs; is refused):
(+ 2 3),(dotimes [i n] …),inc - err-params (Before it runs; is refused):
(defn f [a] …) - err-fuel (While it runs; is refused):
(+ 2 3),(loop [i 0] …),inc,recur - err-divide (While it runs; is refused):
(+ 2 3),(/ a b) - err-index (While it runs; is refused):
(+ 2 3),nth - err-nil (While it runs; is refused):
(+ 2 3),(get m :k),+,{:k v} - err-case (While it runs; is refused):
(+ 2 3),(case x 1 "a" "b"),:k - err-toy (In a toy; runs):
(defobject name {…}),(get m :k),nth,say,str,{:k v}
Style #
- style-small (Small functions; runs):
(+ 2 3),(defn f [a] …),(f a b),(if t … …),(join sep l),=,empty?,str - style-old-state (State that lasts; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,{:k v} - style-new-state (State that lasts; runs):
(defobject name {…}),(get m :k),(let [x (atom v)] …),:k,count,count,do,fnil…
Other spellings #
- spelling-check (A worked-out step; a fragment):
+,roof
Words in brief #
- brief-fixed (The fixed tests and their spellings; runs):
(+ 2 3),(/ (double a) b),(/ a b),(= :rain (:weather (sky))),(contains? (set l) v),(format "%.2f" (double n)),(vec (reverse l)) - brief-swaps (Names that change: the other two shapes; runs):
(+ 2 3),(let [x (atom v)] …),(reset! x (rand-nth l)),(swap! x - n),string? - brief-numbers (Numbers; runs):
(+ 2 3),*,==,abs,atan2,ceil,clamp,compare… - brief-number-kinds (Numbers of other kinds; runs):
(+ 2 3),(/ a b),*',+',-',bigdec,bigint,biginteger… - brief-number-tests (Tests on numbers; runs):
(+ 2 3),(/ a b),decimal?,double?,float?,int?,integer?,nat-int?… - brief-bits (Bits; runs):
(+ 2 3),bit-and,bit-and-not,bit-clear,bit-flip,bit-not,bit-or,bit-set… - brief-truth (True, false and nothing; runs):
(+ 2 3),:k,any?,boolean,boolean?,false?,identical?,identity… - brief-kinds (What kind of value; runs):
(+ 2 3),:k,associative?,char?,coll?,count,counted?,first… - brief-lists (Lists, front and back; runs):
(+ 2 3),butlast,count,drop-last,drop-while,ffirst,fnext,next… - brief-making (Making lists and maps; runs):
(+ 2 3),+,:k,array-map,bounded-count,count,empty,find… - brief-over (Over a list; runs):
(+ 2 3),(fn [a b] …),(if t … …),(map f l),+,:k,coll?,count… - brief-sorted (Sorted maps and sets; runs):
(+ 2 3),:k,<,>,count,rsubseq,sorted-map,sorted-map-by… - brief-fold (Steps that fold; runs):
((fn …) x),(+ 2 3),(fn [a b] …),(if t … …),+,>,cat,completing… - brief-functions (Functions of functions; runs):
((fn …) x),(+ 2 3),(fn [a b] …),count,even?,every-pred,inc,memoize… - brief-text (Text, symbols and keywords; runs):
#"…",(+ 2 3),(let [x (atom v)] …),:k,char,char-escape-string,char-name-string,ident?… - brief-chance (Chance, once more; runs):
(+ 2 3),count,random-sample - brief-toy (A toy's other words; runs):
(defobject name {…}),:k,color,glow-color,glow-colour,my-color,my-glow,say…
Answers to the exercises #
- ans-forms-1 (Forms and values; runs):
(+ 2 3),* - ans-forms-2 (Forms and values; runs):
(+ 2 3),+,str - ans-forms-3 (Forms and values; runs):
(+ 2 3),str,type - ans-forms-4 (Forms and values; runs):
(+ 2 3),{:k v} - ans-names-1 (Names; runs):
(+ 2 3),(let [x (atom v)] …),* - ans-names-2 (Names; runs):
(+ 2 3),(get m :k),(let [x (atom v)] …),str,{:k v} - ans-names-4 (Names; runs):
(+ 2 3),(dotimes [i n] …),(let [x (atom v)] …),(swap! x + n) - ans-text-1 (Text, lists and maps; runs):
(+ 2 3),(join sep l),(map f l),count,upper - ans-text-2 (Text, lists and maps; runs):
(+ 2 3),count,words - ans-text-3 (Text, lists and maps; runs):
(+ 2 3),:k,assoc,{:k v} - ans-text-4 (Text, lists and maps; runs):
(+ 2 3),(range a b),take-last,vec - ans-text-5 (Text, lists and maps; runs):
(+ 2 3),includes?,starts-with? - ans-choices-1 (Tests and choices; runs):
(+ 2 3),(let [x (atom v)] …),:k,<,cond - ans-choices-2 (Tests and choices; runs):
(+ 2 3),(case x 1 "a" "b"),:k - ans-choices-3 (Tests and choices; runs):
(+ 2 3),and,or - ans-choices-4 (Tests and choices; runs):
(+ 2 3),(if t … …),(let [x (atom v)] …),*,count,even?,filter,first - ans-lists-1 (Working over lists; runs):
(+ 2 3),(mapv (fn [x] …) l),(range a b),* - ans-lists-2 (Working over lists; runs):
(+ 2 3),apply,count,frequencies,key,max-key,val - ans-lists-3 (Working over lists; runs):
(+ 2 3),(fn [a b] …),(if t … …),>,count,reduce - ans-lists-4 (Working over lists; runs):
(+ 2 3),(fn [a b] …),filter,starts-with? - ans-fn-1 (Functions; runs):
(+ 2 3),(defn f [a] …),(f a b),str,upper - ans-fn-2 (Functions; runs):
(+ 2 3),(fn [a b] …),(map f l),+ - ans-fn-3 (Functions; runs):
(+ 2 3),(defn f [a] …),(f a b),(if t … …),+,count,empty?,first… - ans-fn-4 (Functions; runs):
(+ 2 3),(if t … …),(loop [i 0] …),*,>,recur - ans-chance-1 (Chance that repeats; runs):
(+ 2 3),+,inc,rand-int - ans-chance-2 (Chance that repeats; runs):
(+ 2 3),shuffle - ans-chance-4 (Chance that repeats; runs):
defobject,say - ans-home-1 (Reading your own home; runs):
(+ 2 3),(if t … …),-,>=,coins - ans-home-2 (Reading your own home; runs):
(+ 2 3),(get m :k),(join sep l),(map f l),:k,house - ans-home-3 (Reading your own home; runs):
(+ 2 3),(= :night (:time (sky))),(if t … …) - ans-home-4 (Reading your own home; runs):
(+ 2 3),(get m :k),(let [x (atom v)] …),-,first,parse-long,split,world-time - ans-toy-1 (A first toy; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - ans-toy-2 (A first toy; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - ans-toy-3 (A first toy; runs):
(defobject name {…}),(get m :k),(if t … …),:k,=,inc,put!,say… - ans-toy-4 (A first toy; runs):
(defobject name {…}) - ans-listen-1 (A toy that listens; runs):
(defobject name {…}),(if t … …),hash-set,lower,say,some,words - ans-listen-3 (A toy that listens; runs):
(defobject name {…}),(get m :k),(if t … …),and,includes?,lower,nil?,not… - ans-dawn-1 (Keeping time; runs):
(defobject name {…}),(get m :k),:k,inc,put!,say,str,{:k v} - ans-dawn-2 (Keeping time; runs):
(= :night (:time (sky))),(defobject name {…}),(if t … …),say - ans-dawn-3 (Keeping time; runs):
(defobject name {…}),(get m :k),name,say,str,weather - ans-dawn-4 (Keeping time; runs):
(defobject name {…}),(if t … …),glow-colour,say - ans-memory-1 (A toy with a memory; runs):
(defobject name {…}),(get m :k),(if t … …),(join sep l),(let [x (atom v)] …),:k,conj,do… - ans-memory-2 (A toy with a memory; runs):
(defobject name {…}),(get m :k),(if t … …),(let [x (atom v)] …),:k,apply,count,empty?… - ans-game-3 (A small game; runs):
(defobject name {…}),(get m :k),(get m k),(if t … …),(let [x (atom v)] …),:k,=,assoc… - ans-designs-1 (Pictures and dances; runs):
design - ans-designs-2 (Pictures and dances; runs):
(defn f [a] …),(dotimes [i n] …),(f a b),(if t … …),(join sep l),(mapv (fn [x] …) l),(range a b),design… - ans-designs-3 (Pictures and dances; runs):
defdance - ans-designs-4-first (Pictures and dances; runs):
defdance - ans-designs-4 (Pictures and dances; runs):
(vec (reverse l)),defdance - ans-house-1 (The house as a form; runs):
(get m :k),(let [x (atom v)] …),+,first,house,roof - ans-house-2 (The house as a form; runs):
window-box - ans-house-3 (The house as a form; runs):
paint,rand-nth - ans-house-4 (The house as a form; runs):
(+ 2 3),(get m :k),(map f l),:k,house,house - ans-limits-1 (Limits, errors and refusals; runs):
(+ 2 3),nth - ans-limits-2 (Limits, errors and refusals; runs):
(+ 2 3),(get m :k),(let [x (atom v)] …),:k,>,cond,or,{:k v} - ans-limits-4 (Limits, errors and refusals; is refused):
(+ 2 3),(vec (range a b))
Written by Claude, Plazmi's writer, for Plazmi, a service of Manatee Media LLC. Text © 2026 Manatee Media LLC. The examples are free to copy, change and run.