Last active
January 11, 2021 05:19
-
-
Save lyxal/d8571d378fb011098b23675df1a9ac8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=================== | |
| Learning Jelly | | |
=================== | |
Programs are made of links. Links are made of chains. Chains are made of atoms. Atoms have a fixed arity. | |
Each link's chains are evaluated according to a set of predefined "rules". | |
Links can be niladic (called with 0 arguments), monadic (called with 1 argument) or dyadic (called with 2 arguments) | |
Nilads have arity 0, monads have arity 1 and dyads have arity 2 | |
Niladic Chains | |
============== | |
These are simple. They start with a nilad and evaluates everything thereafter as a monadic chain. | |
Monadic Chains | |
============== | |
This is where the rules come in. A monadic chain is passed a value "n" and have a flow-through value "x". With each evaluation of a pattern, "x" is updated to be equal to the result of the pattern. We start with "x = n" | |
Let D be a dyad, M be a monad and N be a nilad | |
Pattern : x = | |
D M : Dyad(x, Monad(n)) | |
D N : Dyad(x, Nilad) | |
N D : Dyad(Nilad, x) | |
D : Dyad(x, n) | |
M : Monad(x) | |
Dyadic Chains | |
============= | |
This is where the fun begins. These are passed two arguments, "left" and "right", and has flow-through value "x". The starting value of "x" is usally "x = left", but can vary: | |
If the chain looks like D1 D2 D3..., x = Dyad1(left, right), and the chain becomes D2 D3 ... | |
If the chain looks like N ..., and not N D ..., x = N | |
Else, x = left | |
Let D<n> be a dyad, M be a monad and N be a nilad | |
Pattern : x = | |
D1 D2 N : Dyad2(Dyad1(x, right), Nilad) (if N is a constant) | |
D1 D2 : Dyad1(x, Dyad2(left, right)) | |
D N : Dyad(x, Nilad) | |
N D : Dyad(Nilad, x) | |
D : Dyad(x, right) | |
M : Monad(x) | |
Multiple Chains in a Link | |
========================= | |
Sometimes, chains need to be grouped in a way that explicitly determines their type. In other words, you might need to treat two dyads as a single unit and give that unit arity of 2. Also in other words, you "define" a mini-atom and give it a defined arity. | |
ø means that you would replace the chain in question with a mini-atom of arity 0 | |
µ means that you would replace the chain in question with a mini-atom of arity 1 | |
ð means that you would replace the chain in question with a mini-atom of arity 2 | |
ɓ is like ð, but the order of left and right are switched (temp = right; left = right; right = temp) | |
An example: | |
C+×H is a chain with 4 atoms, and has an arity list of [1, 2, 2, 1] | |
Cð+×µH is a chain with 3 "atoms", and has an arity list of [1, 2, 1] | |
Note that atoms are chunked into the mini-atom until the next chain seperator is reached. | |
Quicks | |
====== | |
Quicks are special things which manipulate links in special ways. For example, they can: group links together, repeated apply links, link links together in a conditional manner, modifiy the arity of links and more. They can be seen to be adding special instructions to links at parse-time. Perhaps a way to think of quicks is as a pre-processor | |
Some example quicks are: | |
+H$ -> $ treats the +H unit as a single monad. | |
+` -> ` turns a dyad into a monad by repeating it's left argument | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment