esolang

FILO

Every value is a stack, and every element of a stack is another stack. A bit is a stack that is empty or not.

2021 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: cat

The idea

FILO dates from 2021. A program is one expression, and the only values are stacks whose elements are stacks too. There are no numbers and no characters. There is the empty stack 0, the argument @, and three operators that push, take the top and pop. Taking the top and popping each fall back to a second value when the stack is empty, and that fallback is the only way to branch.

Read the story

Functions come from a recursive let, and the only way to call them is f*g x, y,. It applies f to the top of x and g to the rest, and pushes the one result onto the other. When g is the function itself, that is a map over a stack.

The specification leaves input and output to the implementation. As the specification suggests, they are stacks of bits. An empty stack is a 0 and any other stack a 1, eight to a byte, low bit first.

The machine

ExpressionGives
@The argument of the function
0The empty stack
x*yy with x pushed onto it
x+yThe top of x, or y if x is empty
x-yx without its top, or y if x is empty
f*g x, y,f of the top of x pushed onto g of the rest, or y if x is empty
[f=x g=y]zz, with f and g defined

The three operators are right associative and equally strong, and there are no brackets for grouping. Evaluation is lazy, so a fallback is worked out only when it is needed.

Example

A cat is the argument itself program.

A cat is the argument itself program.

The Hello world writes its 103 bits as a chain of pushes inside h. Within h, @ is a 1 when h gets a stack that is not empty and a 0 when it gets the empty one. h*h 0*0*0,0, calls h on both, and -0 drops the copy that is all zeros.

Expected: Hello world!

Eight functions take turns down the bits, one for each place in a byte. The sixth flips its bit with @-0*0, which turns an empty stack into a full one and back, so every letter changes case.

Expected: hELLO

Patterns it teaches

  • Stack machines: a stack is the only kind of value, and even a bit is one.

Further

Functional paradigm

Stack-based

Write your own in Run Convert a program from FILO

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: filo.

Command line

shib run filo -e '@' --input 'Hi!'
shib manual filo

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/filo.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org