all repos — hex @ 58b8f7b1acea33aa2d6458d703f312f44b367436

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Fixes
Fabio Cevasco h3rald@h3rald.com
Tue, 24 Dec 2024 14:46:52 +0100
commit

58b8f7b1acea33aa2d6458d703f312f44b367436

parent

9186248d2fa35ee61255ff5dd1912909528665bd

2 files changed, 4 insertions(+), 4 deletions(-)

jump to
M web/contents/learn.htmlweb/contents/learn.html

@@ -157,13 +157,13 @@ <p>...What? You don't even know how to implement a loop or a condition? But it's all the same! It's always values pushed and popped from the stack using symbols!</p>

<p>Alright, let's do something actually useful. I know: let's implement a new operator to implement the <em>factorial</em> of an integer! You never know when you'll need a factorial these days.</p> <p>Here goes:</p> <pre><code>( - $&quot;_n&quot;$$ $:$$ + $"_n"$$ $:$$ ($:_n$$ $0x0$$ $:&lt;=$$) ($0x1$$) ($:_n$$ $:_n$$ $0x1$$ $:-$$ $:factorial$$ $:*$$) $:if$$ - $&quot;_n&quot;$$ $:#$$ -) $&quot;factorial&quot;$$ $:::$$ + $"_n"$$ $:#$$ +) $"_factorial"$$ $:::$$ </code></pre> <p>Woah! That was a mouthful, wasn't it? Before breaking it down, look at the very end of the program: see that {{sum-::}}? That's the symbol to store <em>operator</em> symbols in The Registry. Operator symbols are defined using a quotation, but unlike ordinary quotations (stored using {{sum-:}}), they will be <em>immediately dequoted</em> when pushed on the stack. In other words, our $:factorial$$ operator symbols will behave exactly like one of the built-in native symbol.</p> <p>Let's see what is happening inside the quotation:</p>
M web/contents/spec.htmlweb/contents/spec.html

@@ -480,7 +480,7 @@ 01 01 01

22 $; symbol -$$ $; Lookup second symbol (factorial)$$ 00 01 00 - 23 $; Symbol * + 23 $; Symbol *$$ 14 $; Symbol if$$ 02 02 5f 6e 12 $; Symbol ::$$