Exploring Pyramid Scheme: A Unique Evaluation Style Language
Pyramid Scheme is a programming language that adopts an unconventional evaluation style, replacing parentheses with pyramids. In this article, we will delve into the intricacies of Pyramid Scheme, understanding its unique evaluation style, the available functions, and exploring example programs to grasp its potential applications.
Understanding the Evaluation Style
Similar to LISP-like languages, Pyramid Scheme uses pyramids instead of parentheses for grouping evaluation order. The “root” of evaluation is represented by the ^
character on the first line of the pyramid. Pyramids are formed by lines with /
and \
characters stemming downwards from the ^
, finally closing off with a line of -
s.
A pyramid can either be a leaf or a node. Leaves represent data and closely resemble blank pyramids. Nodes, on the other hand, are created when arguments are supplied. Arguments are introduced by constructing another pyramid with its tip adjacent to the bottom of another pyramid. The number of characters that can fit inside a pyramid determines its capacity.
Available Functions
Pyramid Scheme provides a limited set of functions, each with a specific arity (number of arguments required). Some functions are evaluated, meaning they simply perform operations on their arguments, while others are unevaluated and used for control flow or repeated evaluation.
The available functions include:
-
+
,-
,*
,/
: Basic arithmetic operations -
^
: Exponentiation -
=
: Equality comparison -
<=>
: Comparison returning values based on order -
out
: Printing values -
chr
: Conversion to UTF-8 character -
arg
: Obtaining command line arguments -
#
: Conversion from string to value -
"
: Conversion to string - Identity function
- Logical negation
- Bracket functions for grouping
-
set
: Variable assignment -
do
: Evaluation while a condition is true -
loop
: Evaluation with conditional looping -
?
: If-else statement
Example Programs
To illustrate the capabilities of Pyramid Scheme, let’s explore a couple of example programs.
Truth Machine
The Truth Machine program outputs infinite 1
s when supplied with a 1
and a single 0
when supplied with a 0
. In Pyramid Scheme, this program can be represented as:
^
/ \
/set\
^-----^
/a\ /#\
--- ^---
/ \
/ \
/line \
-------
This program can also be expressed in LISP-like syntax (set a (# line)) (do a (out a))
, or in a Python-like language:
python
a = input()
while a:
print(a)
If-Else Statement
Here’s an example of an if-else statement in Pyramid Scheme. This program prints 1
for truthy values and 0
for falsey values:
^
/?\
^---^
/!\ / \
^---/out\
/?\ -----^
^---^ /0\
/A\ / \ ---
---/out\
^-----
/1\
---
Multiple Evaluations
Pyramid Scheme allows for multiple evaluations of a pyramid, as it can be the child of different nodes. Consider the following example:
“`
^
/+\
^—^
/+\ /*\
^—^—^
/1\ /3\ /4\
“`
This evaluates to (1 + 3) + (3 * 4) = 4 + 12 = 16.
Conclusion
Pyramid Scheme is a captivating programming language with its unique evaluation style using pyramids. By replacing parentheses with pyramids, Pyramid Scheme offers an unconventional approach to programming. By understanding its evaluation style, available functions, and exploring example programs, we can unlock the potential applications of this language. Whether you’re interested in exploring alternative programming paradigms or simply expanding your programming language repertoire, Pyramid Scheme is worth exploring.
We encourage you to dive into the documentation, experiment with Pyramid Scheme, and see where this unique language can take you.
Feel free to ask any questions you may have!
References:
– Repository: Pyramid-Scheme
– Author: ConorOBrien-Foxx
– License: None (Open Source)
Leave a Reply