functional programming - Which Function is the best in terms of Stack Usage Efficiency and Time -


I've written 3 functions, which calculate the number of times when one-element appears in one-list. I tried different inputs and made profiles but I still do not know which function is best in terms of efficiency and time efficiency of stack usage. Please help me

;; Using a Raider (Counting Count-Example 1 [One List of One-Elements] (letfn [(count-aux [list-aux acc] (cond (empty? List-aux) AC: else (if (= ( First list-aux) count-aux (rest list-aux) (inc ACC) (count-aux (rest list-aux)))))) (calculation-aux a-list 0)) ;; Normal counting (calculation example 2 [a-list e-element] (consolidated empty list) 0: and (if (= (first a-list) a-element) (+ 1 (calculation-Example 2 ( Remaining one-list) one element) (calculation-example 2 (the rest one list) an element)))) ;; Using Loop Does It Help? (Empty number-Example 3 [A-list A-element] (Loop [Meristel A-list acount 0] (if (empty mylist) acount (if (= (first mylist) an-element) (recurrence mylist) (Inc acount) acount (repetition mylist))))

loop / recur Version is the correct way Closer can not optimize tail call due to JVM's limitations


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -