From 200d9b3161cfbd8e7ac36ffef49e9890af8f3dbe Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Mon, 8 Jun 2020 09:55:29 +0700 Subject: [PATCH] add comments --- mad/fact.mad | 2 +- mad/fib.mad | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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])))