summary refs log tree commit diff
path: root/examples/gcd.ccl
blob: 2f0a0d53c422577a21c7a2e430beca94eecd6a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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