Whispers v1
Every line is a value or a function of other lines, named by number. The last line runs, and it whispers to the lines it needs.
caird coinheringaahing · Turing complete: unknown · ●●○ moderate
Tested with 5 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
caird coinheringaahing made Whispers, and most of its operators are symbols from mathematics. A line holds a literal, or applies one symbol to the lines it names. >> 1+2 adds the values of lines 1 and 2, >> 3! takes the factorial of line 3, and >> |4| the absolute value of line 4. Nothing runs in order. The last line is evaluated first, and every line it mentions is worked out when it is needed, again each time.
Read the story
The interpreter is one Python file, and Python decides a lot. Whole numbers have no limit, ÷ gives a float, ranges are Python sets, and sets print in the order CPython's hash table keeps them in. This implementation follows the first version, on the v1 branch, which Try It Online runs as Whispers v1.
The machine
Lines are numbered by the ones the interpreter recognises; any other line is skipped and does not count. A line that is called gets its arguments as L and R.
| Line | Does |
|---|---|
> "Hello" > 5 > [1, 2] > π | A literal |
> Input | The next line of input |
>> 1+2 | An operator between two lines: + - ⋅ ÷ * % = < ∪ ∩ ∈ … ⊓ ⊔ ‖ and more |
>> √1 >> 1! >> \|1\| | A prefix, postfix or surrounding operator |
>> Output 1 2 | Print lines 1 and 2 |
>> Each 3 1 | Call line 3 on every item of line 1, as L |
>> While 1 2 >> If 1 2 3 >> For 1 2 | Loops and a conditional |
>> ∀ℙ | A predicate: are all items of L prime? A false one prints ⊥ and stops |
* is a power, ⋅ a product. 1…2 is the range from line 1 to line 2 as a set. A predicate line such as >> ∀ℙ also matches some operator lines, so >> ∑2 is read as a predicate, not a sum.
Example
The second program squares the range 1 to 5, with line 5 running line 4 on each item.
The second program squares the range 1 to 5, with line 5 running line 4 on each item. The last one turns a list into a set. CPython's table has 8 slots, and 8 lands in slot 0, so it prints first.
Patterns it teaches
Whispers is close to a dataflow graph.
Whispers is close to a dataflow graph. Every line is a node, and the numbers are the edges. Nothing is stored, so a line used twice is computed twice.
Try this
- Print the sum of two numbers read from input.
- Print the squares of 1 to 10 with
Each. - Hard: test whether every number in a range is prime with a predicate.
Further
- The reference interpreter, in Python
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Whispers v1
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: whispers.
Command line
shib run whispers -e '> Input
>> 1!
>> Output 2' --input '10
'shib manual whispersSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/whispers.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language