Skip to main content

The Craft of Emacs

Pairs: car and cdr

1 hour

Sit back and have a read through your xx‑‑read‑colours function.

If you’re still a bit suspicious about how it terminates, why not try evaluating it in the *scratch* buffer and writing out the steps?

Define the helper function xx‑‑read‑colours

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

xx‑‑read‑colours takes no arguments

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

Get a colour string as input

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

Bind it to colour

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

If it is blank

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

Return nil

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

If not, construct a list

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

with colour as the first element

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)

and the remaining colours to be inputted as the rest.

(defunxx‑‑read‑colours
()
(let
(
(colour
(read‑string"What colour is the thread? ")
)
)
(if
(string‑blank‑pcolour)
nil
(conscolour
(xx‑‑read‑colours)
)
)
)
)