From da312e375eb0a0758a4dd72e287d3aba86c04d99 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 10 Jun 2017 23:18:31 +0200 Subject: Add FIRST & THIRD almost FORTH --- buzzard/demo5.th | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 buzzard/demo5.th (limited to 'buzzard/demo5.th') diff --git a/buzzard/demo5.th b/buzzard/demo5.th new file mode 100644 index 0000000..d16ca1e --- /dev/null +++ b/buzzard/demo5.th @@ -0,0 +1,27 @@ +( recursive factorial. given x on top, followed by ) +( an "accumulator" containing the product except for x! ) + +: fact-help2 + + dup if + swap over swap + * + swap 1 - + fact-help2 + then +; + +: fact + + 1 swap + fact-help2 + drop +; + +: demo5 + + " The factorial of 3 is: " 3 fact . cr + " The factorial of 5 is: " 5 fact . cr +; + +demo5 -- cgit v1.2.3