Kipple

From Esolang
Jump to navigation Jump to search

Kipple is a minimalistic esoteric programming language with a set of stacks, four operators, and a single control structure. Kipple was designed by Rune Berge in March, 2003.

Stacks

The stacks are named a-z and contain 32-bit signed integers. There is also a special stack, @, to make outputting numbers more convenient. When a number is pushed onto @, the ASCII values of that number's digits are in fact pushed instead. The @ stack is an example of a wimpmode.

Input is pushed onto stack i before the program is executed; after execution finishes, anything on stack o is popped to output. Since this is Kipple's only IO mechanism, interacting with a Kipple program is impossible.

Operators

An operand can either be a stack identifier or a nonnegative integer (0 to 2147483647).

> Push left operand onto right stack
< Push right operand onto left stack
+ Push the sum of the right operand and the topmost item of the left stack onto the left stack
- Push the topmost left stack item minus the right operand onto the stack
? Takes only one operand; clears the left stack if its topmost item is 0

< and > are the same operator, working in different directions. If the right operand of <, + or - or the left operand of > is a stack identifier, its top value is popped and used as the operand instead. The topmost item of an empty stack is considered to be 0, and popping from an empty stack always return 0.

If the right-hand operand of one operator matches the left-hand operand of the next, they can be merged, e.g. a<b b>c can be written as a<b>c.

The string preprocessor is not a standard, but the official interpreter supports it.

Control structure

The control structure is

(stack-identifier code)

where stack-identifier is a-z and code is any sort of code, possibly including additional loops. The code will be run as long as the stack is not empty.

Examples

Hello, world!

This program prints "Hello World!":

33>o 100>o 108>o 114>o 111>o 87>o 32>o 111>o 108>o 108>o 101>o 72>o

Alternate version using the string preprocessor:

"Hello World!">o

Cat

A program that copies its input to output, like UNIX cat.

(i>o)

Reverse cat

(i>p)(p>o)

Fibonacci numbers

Prints the first 25 numbers of the Fibonacci sequence.

24>n 0>t 1>a
(n-1
  a+0
  t<a>b+a
  c<b>a<c
  n?
)
(t>@
  (@>o)
  32>o
)

The first loop generates the numbers, and the second loop converts them to ASCII.

Computational class

Kipple is Turing-complete; a direct proof by simulation is provided in the form of this Brainfuck interpreter written in Kipple, since Brainfuck is known to be Turing-complete.

External resources