3 ms·
Is there any interesting piece of code that might help me see this working to its true potential? I tried the factorial function expecting it to show all the re
by alokm 14y ago
Is there any interesting piece of code that might help me see this working to its true potential? I tried the factorial function expecting it to show all the recursive calls. What can I expect to see here? Call trace over multiple functions?
EDIT: Just tried this , atleast this shows the last calls made to the functions
(defn my-add [a b]
(+ a b))
(defn fact[x]
(if (<= x 1) 1 (* x (fact (- x 1)) )))
(my-add (fact (my-add 3 3)) (fact (my-add 2 5)))
---------------
OUTPUT
(defn my-add [||720|| ||5040||]
(+ ||720|| ||5040||))
(defn fact[||1||]
(if (<= ||1|| 1) 1 (* ||1|| (fact (- ||1|| 1)) )))
(my-add (fact (my-add 3 3)) (fact (my-add 2 5)))|| => 5760||
- lmarinho 14y agoA little example I've come up with is writing a bunch of tests for a function you are implementing and seeing them automatically executed. Try to fix fib by changing a, b and i values: (defn fib [n] (loop [a 1, b 1, i 1] (if (= i n) a (recur b (+ a b) (inc i))))) (= (fib 0) 0) (= (fib 1) 1) (= (fib 2) 1) (= (fib 3) 2) (= (fib 4) 3) (= (fib 10) 55)
- splattne 14y agoHello world: (javax.swing.JOptionPane/showMessageDialog nil "Hello World")