diff --git a/mad/fact.mad b/mad/fact.mad index 9ecaa3e..c791644 100644 --- a/mad/fact.mad +++ b/mad/fact.mad @@ -1,6 +1,6 @@ ;; Functions to calculate factorial -;; Recursive version +;; Recursive version, not tail call optimized (def recFact (fn (n) (if (< n 2) 1 (* n (recFact (- n 1)))))) ;; Apply version diff --git a/mad/fib.mad b/mad/fib.mad index 2883128..f093016 100644 --- a/mad/fib.mad +++ b/mad/fib.mad @@ -6,6 +6,6 @@ ;; Return the sum of the last 2 numbers in a sequence (def sumOfLast (fn (l) (+ (last l) (get l (- (len l) 2))))) -;; Faster version, return vector of n numbers +;; Faster version, return vector of n numbers, tail call optimized (def fibListRec (fn (n l) (if (< (len l) n) (fibListRec n (push l (sumOfLast l))) l))) (def fibList (fn (n) (fibListRec n [0 1])))