Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sicp-clojure.core=> (dotrace [iter] (fact-lin-it2 6))
TRACE t1666: (iter 1 1)
TRACE t1667: | (iter 1 2)
TRACE t1668: | | (iter 2 3)
TRACE t1669: | | | (iter 6 4)
TRACE t1670: | | | | (iter 24 5)
TRACE t1671: | | | | | (iter 120 6)
TRACE t1672: | | | | | | (iter 720 7)
TRACE t1672: | | | | | | => 720
TRACE t1671: | | | | | => 720
TRACE t1670: | | | | => 720
TRACE t1669: | | | => 720
TRACE t1668: | | => 720
TRACE t1667: | => 720
TRACE t1666: => 720
720
sicp-clojure.core=>
sicp-clojure.core=> (dotrace [factorial-lin-recur] (factorial-lin-recur 6))
TRACE t1678: (factorial-lin-recur 6)
TRACE t1679: | (factorial-lin-recur 5)
TRACE t1680: | | (factorial-lin-recur 4)
TRACE t1681: | | | (factorial-lin-recur 3)
TRACE t1682: | | | | (factorial-lin-recur 2)
TRACE t1683: | | | | | (factorial-lin-recur 1)
TRACE t1683: | | | | | => 1
TRACE t1682: | | | | => 2
TRACE t1681: | | | => 6
TRACE t1680: | | => 24
TRACE t1679: | => 120
TRACE t1678: => 720
720
@l1x

This comment has been minimized.

Copy link
Owner Author

commented Dec 23, 2013

The following would be better:

     (factorial 6)
      (* 6 (factorial 5))
      (* 6 (* 5 (factorial 4)))
      (* 6 (* 5 (* 4 (factorial 3))))
      (* 6 (* 5 (* 4 (* 3 (factorial 2)))))
      (* 6 (* 5 (* 4 (* 3 (* 2 (factorial 1))))))
      (* 6 (* 5 (* 4 (* 3 (* 2 1)))))
      (* 6 (* 5 (* 4 (* 3 2))))
      (* 6 (* 5 (* 4 6)))
      (* 6 (* 5 24))
      (* 6 120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.