Logo
Explore Help
Sign In
intercal/sybil
1
0
Fork 0
You've already forked sybil
Code Issues Pull Requests Releases Wiki Activity
Files
fe2a83174fa856752ac7b352ec4123a42e3337e0
sybil/examples/factorial.sy

27 lines
315 B
Plaintext
Raw Normal View History

Change `if` function stack ordering, add some basic math ops to Int, add factorial example * `if` function stack ordering is changed to use condition, if-false, if-true (bottom to top). This is so we can pass a value on top of the stack directly to a new `if` in a condition, so we don't have to store a new value in a new variable. * Add __splat__ and __minus__ functions to Int * Add * and - builtins, which call the __splat__ and __minus__ functions of the top stack item, respectively. * Add factorial example because now factorials are possible with this skeleton implementation, albeit a little hacky with the recursion. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-11 11:10:14 -08:00
[ :x x x ] :dup
[
dup!
[dup! 1 -! factorial! *!]
[:_ 1]
if!
]
:factorial
[
dup! print!
"! = " print!
factorial!
println!
]
:do-factorial
1 do-factorial!
2 do-factorial!
3 do-factorial!
4 do-factorial!
5 do-factorial!
6 do-factorial!
7 do-factorial!
8 do-factorial!
9 do-factorial!
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.5 Page: 48ms Template: 4ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API