From a76977af62010a392c16010c367185e61e856ffe Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 30 Oct 2019 20:04:56 +0100 Subject: mv to docs --- docs/buzzard/demo4.th | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docs/buzzard/demo4.th (limited to 'docs/buzzard/demo4.th') diff --git a/docs/buzzard/demo4.th b/docs/buzzard/demo4.th new file mode 100644 index 0000000..3f9a76d --- /dev/null +++ b/docs/buzzard/demo4.th @@ -0,0 +1,30 @@ +( compute factorial recursively ) +( take x as input, return x! and x as output ) + +: fact-help + + dup if + 1 - ( leave x-1 on top ) + fact-help ( leave x-1, [x-1]! ) + 1 + ( leave x, [x-1]!, x ) + swap over swap ( leave [x-1]!, x, x ) + * ( into x!, x ) + swap ( into x, x! ) + else + 1 swap + then +; + +: fact + + fact-help + drop + +; + +: demo4 + " 4 factorial is: " 4 fact . cr + " 6 factorial is: " 6 fact . cr +; + +demo4 -- cgit v1.2.3