Part II. Making things · this page as markdown

A toy that listens

A verb waits to be played. A toy that listens hears what's said near it, and can answer. This chapter makes a parrot, a riddle stone and a mirror, and shows how to be good company: a toy that answers everything soon wears thin.

:on-hear #

A toy with :on-hear hears every line said at your home, by you, a neighbour or a visitor. It is a function of three values: the toy, who spoke, and what they said:

#parrot
(defobject parrot
  {:name "Parrot"
   :on-hear (fn [self who text]
              (when (includes? (lower text) "cracker")
                (say self "Cracker! Cracker!")))})
It answers
The parrot is ready.
Played
> say would you like a cracker
[Juniper's parrot] Cracker! Cracker!
> say lovely weather

The parrot heard both lines and answered one. lower makes the text small letters first, so "Cracker" and "CRACKER" are heard too.

Spoken to, or overheard #

Words can be said to a toy (say hello to the parrot, or say to the parrot: hello) or near it, to nobody in particular. A toy can tell: (:spoken-to self) is true when the words were said to it. And when they were said to someone or something else, (:to self) says whom.

A toy that answers only when it's spoken to stays out of other people's conversations:

#riddle-stone
(defobject riddle-stone
  {:name "Riddle stone"
   :state {:answer "echo"}
   :verbs {:tap (fn [self who]
                  (say self "I answer every call and never speak first. What am I?"))}
   :on-hear (fn [self who text]
              (when (:spoken-to self)
                (if (includes? (lower text) (:answer self))
                  (say self "An echo. That's the one.")
                  (say self "Not that one. Think of a valley."))))})
It answers
The riddle stone is ready.
Played
> tap riddle stone
[Juniper's riddle stone] I answer every call and never speak first. What am I?
(To answer: answer <your words>, or say <your words> to the riddle stone.)
> answer a bird
[Juniper's riddle stone] Not that one. Think of a valley.
> say an echo, surely
> say to the riddle stone: an echo
[Juniper's riddle stone] An echo. That's the one.

Three things to notice. A verb's line that asks a question, from a toy that listens, is followed by a line saying how to answer. answer speaks to the thing that last asked. And "an echo, surely", said to nobody, was overheard and left alone.

Matching words #

includes? finds a piece of text anywhere, which is sometimes too much: "bell" is in "bellow". Three other ways to look:

match makes a parrot that listens for a whole phrase:

#parrot-match
(defobject parrot
  {:name "Parrot"
   :on-hear (fn [self who text]
              (when-let [m (match text "i love *")]
                (say self (str "You love " (first m) "! You love " (first m) "!"))))})
It answers
The parrot is ready.
Played
> say I love the roses
[Juniper's parrot] You love the roses! You love the roses!
> say I'd love some tea

"I'd love some tea" doesn't fit "i love *", so the parrot keeps quiet.

Turning words round #

reflect turns a line round, as a mirror would: I and you, my and your change places, and the verbs follow:

#mirror
(defobject mirror
  {:name "Mirror"
   :on-hear (fn [self who text]
              (when (:spoken-to self)
                (say self (str (reflect text) "?"))))})
It answers
The mirror is ready.
Played
> say to the mirror: I think you are lovely
[Juniper's mirror] You think I am lovely?
> say to the mirror: my garden needs rain
[Juniper's mirror] your garden needs rain?

reflect keeps capitals where they were: "I" came back "You" at the start of a sentence, and "my", written small, came back "your".

Knowing who spoke #

who is who spoke, as for a verb: "@mira" for a neighbour, "@you" for the toy's maker. A toy can greet its maker differently:

#doorbell
(defobject doormat
  {:name "Doormat"
   :on-hear (fn [self who text]
              (when (:spoken-to self)
                (say self (if (= who "@you")
                            "Welcome home."
                            (str "Wipe your feet, " who ".")))))})
It answers
The doormat is ready.
Played
> say hello to the doormat
[Juniper's doormat] Wipe your feet, Mira.
Played
> say hello to the doormat
[Your doormat] Welcome home.

Good company #

Words reach every listening toy at your home, so a toy that answers everything answers over every conversation. A few habits keep a listener pleasant:

Try it #

  1. Make an owl that says "Hoo." when it hears the word "night", and only as a whole word.
  2. Give the riddle stone a second riddle, chosen by a count in its state.
  3. Make a toy that answers "Bless you." to "achoo", but only when nobody was spoken to.
  4. Make a mirror that answers only its maker.

Recap #

Next: a toy that keeps time.

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.