Skip to content

Instantly share code, notes, and snippets.

@mjg123
Created July 25, 2011 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjg123/1104951 to your computer and use it in GitHub Desktop.
Save mjg123/1104951 to your computer and use it in GitHub Desktop.
Why can't I recur here?
(defn calculate
"A list of coin-values from coins, which sum to target"
[coins target]
(let [coin (max-coin coins target)]
(cond
(not coin) (js-alert "No solution")
(= coin target) (list coin)
(< coin target) (cons coin (recur coins (- target coin))))))
(defn calculate
"Make the value of target out of values in the list of coins"
([coins target]
(reverse (calculate coins target (list))))
([coins target so-far]
(let [coin (max-coin coins target)]
(cond
(not coin) (js-alert "No solution")
(= coin target) (cons coin so-far)
(< coin target) (recur coins (- target coin) (cons coin so-far))))))
@mjg123
Copy link
Author

mjg123 commented Jul 25, 2011

AssertionError Assert failed: Can't recur here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment