# Pyramid Scheme

*For the mostly-unrelated dialect of Scheme which targets EVM, see the external article "Write your next Ethereum Contract in Pyramid Scheme".*

Paradigm(s) | declarative |
---|---|

Designed by | Conor O'Brien |

Appeared in | 2017 |

Computational class | Turing complete |

Reference implementation | [1] |

Influenced by | Lisp |

File extension(s) | `.pyr` , `.pyra` |

Pyramid Scheme is an esoteric programming language created by Conor O'Brien in early 2017. It is a dialect of Lisp, but it uses ascii-art pyramid structures as opposed to brackets.

## Etymology

The name is a joke on the name of a different Lisp dialect called Scheme, and its similarity to a (widely frowned-upon and illegal) business model called the pyramid scheme.

## Sample programs

### If/Else statement

The following is an implementation of an if-else statement in pyramid scheme. It prints if A is 1 for truthy, and 0 if it is falsey

^ ^ / \ / \ /set\ / \ ^-----^ / ? \ /A\ /1\ ^-------^ --- --- /!\ / \ ^--- /out\ / \ ^----- / ? \ /0\ ^-----^ --- /A\ / \ --- /out\ ^----- /1\ ---

This is equivalent to the lisp-like syntax:

(set A 1) (? (! (? A (out 1))) (out 0))

### Modulo function

Pyramid scheme does not have an implementation of the modulo function. A modulo of a number has to, therefore, be calculated with repeated subtraction. The following implements the *mod(a,b)* function:

^ ^ ^ ^ / \ / \ / \ / \ /set\ /set\ / \ /out\ ^-----^ ^-----^ / \ -----^ /a\ / \ /b\ / \ / \ /a\ --- /33 \--- /16 \ / loop \ --- ----- ----- ^-----------^ / \ / \ / \ /set\ / <=> \ ^-----^ ^-------^ /a\ /-\ / \ / \ --- ^---^ /<=>\ /-1 \ /a\ /b\ ^-----^ ----- --- --- /a\ /b\ --- ---

which is equivalent to lisp-like:

(set a 33) (set b 16) (loop (<=> (<=> a b) -1) (set a (- a b))) (out a)

## External resources

- Pyramid Scheme on GitHub. Implemented in Ruby.
- Hello world in Pyramid Scheme on TIO
- Lisp-like to Pyramid Scheme compiler in Python.
- Marcin Konowalczyk, “Macro-driven metalanguage for writing Pyramid Scheme programs, SIGBOVIK 2021 proceedings p. 227; also has an associated talk.