kempe-0.2.0.9: examples/factorial.kmp
loop : Int Int -- Int
=: [ swap dup 0 =
if( drop
, dup 1 - dip(*) swap loop )
]
; tail recursive factorial
;
; see C example: https://wiki.c2.com/?TailRecursion
fac_tailrec : Int -- Int
=: [ 1 loop ]
; naïve factorial
fac : Int -- Int
=: [ dup 0 =
if( drop 1
, dup 1 - fac * )
]
%foreign armabi fac
%foreign armabi fac_tailrec