Chaining Rules Cheat-Sheet
If you don't know what chaining rules are, it may help to revisit the beginners' page. Essentially, if multiple chains are written sequentially (whether they be outer chains within a link or inner chains within outer chains), Jelly matches specific patterns based on their arities and walks down the chain, evaluating based on the pattern. You can think of it as there being an accumulating value that changes as the interpreter processes the chain.
If a nilad appears without being part of a valid pattern, it will output the current value to STDOUT (without a trailing newline) and set the current value to the nilad's result (this is known as "smash-printing" because multiple nilads placed together will smash their values to STDOUT with no separator).
The left argument will be α
and the right argument will be ω
. The current value will be λ
. Nilads will be represented by digits, monads by capital letters, and dyads by mathematical operations like + × ÷
.
Leading Constant Chains
A leading constant chain (LCC) is a special type of chain that starts with a nilad and is followed by monads, dyad-nilad pairs, and nilad-dyad pairs. Essentially, the nilad must not be paired with a dyad immediately after it. You can think of it as a chain that takes no arguments (i.e. is niladic) because it begins with a nilad itself and then follows it with a chain of monadic-like operations. Certain chaining rules depend on this.
Niladic Chains
- If the chain starts with a nilad
κ
, thenα = κ
and the rest of the chain is evaluated monadically. - Otherwise,
α = 0
and the entire chain is evaluated monadically.
Note that this means an empty chain will just evaluate to 0
.
Monadic Chains
- If the chain starts with an LCC
κ ...
, thenλ = κ
to start and the rest of the chain is considered. - Otherwise,
λ = α
and the entire chain is considered.
Pattern | New λ value |
Arities / Name |
---|---|---|
+ F ... |
λ + F(α) |
2,1-chain |
+ 1 ... |
λ + 1 |
2,0-chain / dyad-nilad pair |
1 + ... |
1 + λ |
0,2-chain / nilad-dyad pair |
+ |
λ + α |
Lone Dyad |
F |
F(λ) |
Lone Monad |
Dyadic Chains
- If the chain starts with an LCC
κ ...
, thenλ = κ
to start and the rest of the chain is considered. - If the chain starts with three dyads
+ × ÷ ...
, thenλ = α + ω
to start and the rest of the chain is considered. - Otherwise,
λ = α
and the entire chain is considered.
Pattern | New λ value |
Arities / Name |
---|---|---|
+ × 1 ... |
(λ + ω) × 1 * |
2,2,0-chain |
+ × |
λ + (α × ω) |
2,2-chain |
+ 1 ... |
λ + 1 |
2,0-chain / dyad-nilad pair |
1 + ... |
1 + λ |
0,2-chain / nilad-dyad pair |
+ |
λ + ω |
Lone Dyad |
F |
F(λ) |
Lone Monad |
* The 2,2,0-chain rule only applies if the nilad is part of an LCC; that is, the nilad is not followed by a dyad.