Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update src/koans/13_recursion.clj #29

Closed
wants to merge 1 commit into from

2 participants

@eric-hu

Made a separate function for the factorial function applied to bigints.

The reason for this is that the user gets a java.lang.StackOverflowError exception after successfully implementing a solution for a koan.

The koan in question is titled "Simple things may appear simple.", though there are a few more koans after (but they can be solved in the same step as this one).

eric-hu Update src/koans/13_recursion.clj
Made a separate function for the factorial function applied to bigints.

The reason for this is that after successfully implementing a solution for the "Simple things may appear simple." koan and the other non-bigint factorial koans, the `script/run` application throws a java.lang.StackOverflowError.  Instead, it should signal to the user that he's working on the next koan.
514e17f
@trptcolin trptcolin referenced this pull request from a commit
@trptcolin trptcolin Bump koan-engine
refs #29
1cfa85c
@trptcolin
Owner

Hi Eric - sorry it's taken me such a long time to get to this.

I think there are 2 separate issues here: the first is when a StackOverflowError gets thrown, you don't see which koan was the one that failed, and the second is that you need to change the function definition after you've already filled it in.

I definitely think the first one is a bug (and I've addressed that in master), but the second one is behavior that I actually like, since it's the sort of thing we do in programming all the time (improving existing code).

So I'm going to go ahead and close this - thanks for pointing this out!

@trptcolin trptcolin closed this
@eric-hu

No prob, Colin. Your logic makes sense.

Thanks for maintaining the koans!

@urthbound urthbound referenced this pull request from a commit in urthbound/clojure-koans
@trptcolin trptcolin Bump koan-engine
refs #29
574331f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2012
  1. Update src/koans/13_recursion.clj

    eric-hu authored
    Made a separate function for the factorial function applied to bigints.
    
    The reason for this is that after successfully implementing a solution for the "Simple things may appear simple." koan and the other non-bigint factorial koans, the `script/run` application throws a java.lang.StackOverflowError.  Instead, it should signal to the user that he's working on the next koan.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/koans/13_recursion.clj
View
7 src/koans/13_recursion.clj
@@ -16,6 +16,9 @@
(defn factorial [n]
__)
+(defn factorial-bigint [n]
+ __)
+
(meditations
"Recursion ends with a base case"
(= true (is-even? 0))
@@ -45,7 +48,7 @@
(= 24 (factorial 4))
"You can even deal with very large numbers"
- (< 1000000000000000000000000N (factorial 1000N))
+ (< 1000000000000000000000000N (factorial-bigint 1000N))
"But what happens when the machine limits you?"
- (< 1000000000000000000000000N (factorial 100003N)))
+ (< 1000000000000000000000000N (factorial-bigint 100003N)))
Something went wrong with that request. Please try again.