ThinkThen

Beatles Bench pages
Scripts
What Jev knows
Tune your bar
Beatles Bench · The ten functions

Store and reuse questions.

The talk's slide: Store and reuse questions.
Open the slide at full size.

A question file is a small recipe. decide holds the question. true and false say what yes and no mean. threshold sets the band 0.2:0.8. An answer of 0.8 or more is yes, and an answer under 0.2 is no. on picks the title and the album from each record. The request sends only those two fields.

Here a band plays only songs the Beatles wrote. The file asks whether a Beatle wrote a song. decide @original.json runs the recipe on one song.

The numbers come from the bench's songwriter list.

original.json, the question file
{
  "decide": "Did a Beatle write this song?",
  "true": "John, Paul, George, or Ringo wrote it.",
  "false": "Someone else wrote it. It is a cover.",
  "threshold": "0.2:0.8",
  "on": ["/title", "/album"]
}

Run it

decide prints true for Something and exits 0.
printf '%s\n' '{"title":"Something","album":"Abbey Road"}' |
  thinkthen decide @original.json
code=$?
echo "exit $code"
Output
true
exit 0
exit 0

The lesson

George Harrison wrote Something. The answer is right. The exit code carries the answer too: 0 for yes, 1 for no, and 3 for not sure. The next page puts that code to work in a script.

Write the question once in a file, and every run asks it the same way.