From 6fa64679e24b2bef4aee49657df1b2f411b18392 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Wed, 26 Mar 2025 20:22:14 +0300 Subject: Add examples as tests --- examples/gcd.ccl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/gcd.ccl (limited to 'examples/gcd.ccl') diff --git a/examples/gcd.ccl b/examples/gcd.ccl new file mode 100644 index 0000000..2f0a0d5 --- /dev/null +++ b/examples/gcd.ccl @@ -0,0 +1,25 @@ +/ Euclid gcd +/ Last 2 numbers on the stack are arguments +/ Result is passed through the stack too +F { + / Parse arguments into variables + &a=a + &b=b + + / If a == b then exit with it + $ab?#; + + b[-] &c=c / a - b + &f^+=f c ( / if a - b > 0 (or a > b) + $c $b + ^=f#) f ( / else + $b a[-] $a + #) + + / Call ourselves but + / with simpler case + @F +} + +/ gcd(4, 5) +^++++ ^+++++ @F -- cgit 1.4.1