Grocery List
A program is a shopping list. Only the first letter of each item matters, so "eggs" and "espresso" do the same thing.
PuzzleHunter84, 2009 · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
PuzzleHunter84 made Grocery List in 2009. A program starts with a store name, then a blank line, then one food item per line. Each letter of the alphabet is a command, and an item runs the command of its first letter.
Read the story
Some commands also look at the rest of the item. n pushes the number of letters in the item, so "nectarines" pushes 10. v pushes the first letter of the next item and skips it. The joke is that any real shopping list is a program, though most of them crash or do nothing useful.
The machine
A stack of integers. Popping an empty stack gives 0. "Top" is the top value, "next" the one below.
| Letter | Does |
|---|---|
a m | Add, multiply |
s d r | Top minus next, top divided by next (rounded down), top mod next |
g z | 1 if top > next, else 0; logical not |
c f x k | Dup, swap, drop, clear the stack |
b u | Bring the bottom value to the top; send the top to the bottom |
n w | Push the item's letter count; push 100 |
v | Push the first letter of the next item, and skip that item |
y | Remove the stack item that many places down (the item's letter count) |
h | Pop a value, take it mod 26, and run that letter (0 is a) |
j | Pop n and skip the next n items |
l ... e | Loop while the top is not 0 (checked at both ends, not popped) |
i | Read a character (0 at end of input) |
o p | Pop and print as a number, as a character |
q t | Nothing; stop |
Dividing by zero stops the run.
Example
This is the cat program, which it compares to brainfuck's ,[.,].
This is the cat program, which it compares to brainfuck's ,[.,]. Ice cream reads a character, lettuce opens a loop, popcorn prints, imported bisque reads again, and eggs loop back while the character is not 0. Tunafish ends the shopping trip.
Patterns it teaches
- Stack machines: a full set of stack and arithmetic operations.
- Camouflage: the code passes as a note on the fridge.
- Encoding tricks: an item's first letter is the opcode and its length is data.
Try this
- Print the number 100 with a two-item list.
- Print
A(65): find food items whose letter counts multiply or add to 65. - Hard: read a character and print it in upper case.
Further
See also
Stack-based
Write your own in Run Convert a program from Grocery List
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: grocery-list.
Command line
shib run grocery-list -e 'Corner Shop
watermelon
oranges'shib manual grocery-listSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/grocery-list.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org