Fynyl
A golfing stack language on top of Ruby, where every command is one character and blocks of commands can be mapped, folded and zipped.
Conor O'Brien · 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
Fynyl is a stack language by Conor O'Brien, run by a single Ruby file. Its values are Ruby's own, integers of any size, strings, arrays and booleans, plus blocks, which are pieces of program kept as values. Numbers are written with an underscore for minus, so _4 is minus four, and (1 2 3) collects whatever is pushed inside the brackets into one array.
Read the story
The power is in the metas. m, f, z and t take the next character as a function, so 5rf* builds 1 to 5 and folds it with *, which is 120, and 3rm{d*} squares each of 1, 2 and 3. Whatever is left on the stack is printed at the end, one item per line, in Fynyl's own notation.
The machine
| Code | Does |
|---|---|
12 _12 "text" 'c `c | Numbers, minus numbers, strings ("" for a quote), a character, its code | |
( … ) { … } @x | An array; a block; a block of one token |
+ - * / % ^ | Ruby's arithmetic; * also repeats strings and runs blocks, / splits |
= < > :< :> .< .> | Compare; minimum and maximum |
d $ ~ y , | Duplicate, drop, swap, over, pair |
r R Z D j s | Ranges, digits or characters, join, size |
m f z t v V | Map, fold, zip, table, vectorise, followed by the function |
? w W L ! | If, while, loop, factorial or run a block |
o O p P | Print plainly or in Fynyl's notation, with or without a newline |
&x .&x | Store into a variable or a function named x |
This implementation follows fynyl.rb, the interpreter Try It Online runs. It is a subset. Integers, strings, arrays, blocks and booleans work as in Ruby; floats, rationals, complex numbers, format strings, files and a few rarer commands are left out, and stop the program with a note saying so.
Example
The third program maps a block that duplicates and multiplies over 1 to 3, and p prints the array in…
The third program maps a block that duplicates and multiplies over 1 to 3, and p prints the array in Fynyl's notation. The fourth zips two arrays with +. The last leaves two numbers on the stack, which the end of the program prints, minus four written the Fynyl way.
Patterns it teaches
- Stack machines: one stack, with arrays and blocks as values on it.
- Code golf: a meta and the character after it replace a whole loop.
Try this
- Print the sum of the numbers 1 to 100.
- Print the squares of 1 to 10 on separate lines.
- Hard: read a line and print it with its words reversed.
Further
- The Ruby interpreter, with the command table in its README
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Fynyl
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: fynyl.
Command line
shib run fynyl -e '5!o'shib manual fynylSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/fynyl.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language