Skip to main content

The Craft of Emacs

Quotes, lists and lambdas

1 hour 30 minutes

Here’s a copy of the code you’ve written:

(defunxx
()
(interactive)
(get‑buffer‑create"*xx*")
(switch‑to‑buffer"*xx*")
(erase‑buffer)
(xx‑‑insert‑line"Skeins")
(xx‑‑insert‑line"======")
(let*
(
(strands
(xx‑‑read‑positive"No. strands: ")
)
(colours'
(blackmagentapink)
)
(stitches
(seq‑map'xx‑‑read‑stitchescolours)
)
(num‑skeins‑function
(lambda
(count)
(xx‑‑num‑skeinsstrandscount)
)
)
(num‑skeins
(seq‑mapnum‑skeins‑functionstitches)
)
(total‑num‑skeins
(apply'+num‑skeins)
)
)
(xx‑‑insert‑line
(concat"No. strands: "
(number‑to‑stringstrands)
)
)
(xx‑‑insert‑line
(concat"Total no. skeins: "
(number‑to‑stringtotal‑num‑skeins)
)
)
(seq‑mapn
(lambda
(colournum)
(xx‑‑insert‑line
(concat"No. "
(symbol‑namecolour)
" skeins : "
(number‑to‑stringnum)
)
)
)
coloursnum‑skeins)
)
)
(defunxx‑‑read‑stitches
(colour)
(let
(
(name
(symbol‑namecolour)
)
)
(xx‑‑read‑positive
(concat"How many stitches are "name"? ")
)
)
)
(defunxx‑‑insert‑line
(text)
(inserttext)
(newline)
)
(defunxx‑‑num‑skeins
(strandsstitches)
(ceiling
(/
(float
(*strandsstitches)
)
4800.0)
)
)
(defunxx‑‑read‑positive
(prompt)
(let
(
(input
(read‑numberprompt)
)
)
(if
(and
(integerpinput)
(>input0)
)
input
(message"Enter an integer greater than 0.")
(sit‑for1)
(xx‑‑read‑positiveprompt)
)
)
)
xx.el