Fixes
Fabio Cevasco h3rald@h3rald.com
Tue, 24 Dec 2024 14:46:52 +0100
2 files changed,
4 insertions(+),
4 deletions(-)
M
web/contents/learn.html
→
web/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>( - $"_n"$$ $:$$ + $"_n"$$ $:$$ ($:_n$$ $0x0$$ $:<=$$) ($0x1$$) ($:_n$$ $:_n$$ $0x1$$ $:-$$ $:factorial$$ $:*$$) $:if$$ - $"_n"$$ $:#$$ -) $"factorial"$$ $:::$$ + $"_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.html
→
web/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 ::$$