Skip to content

Commit 450b458

Browse files
Define nthPrime() before called by secondPrime() (#110)
Swap order of implementation
1 parent 0c6691b commit 450b458

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/scala/scalatutorial/sections/LazyEvaluation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ object LazyEvaluation extends ScalaTutorialSection {
2121
* This is ''much'' shorter than the recursive alternative:
2222
*
2323
* {{{
24-
* def secondPrime(from: Int, to: Int) = nthPrime(from, to, 2)
2524
* def nthPrime(from: Int, to: Int, n: Int): Int =
2625
* if (from >= to) throw new Error("no prime")
2726
* else if (isPrime(from))
2827
* if (n == 1) from else nthPrime(from + 1, to, n - 1)
2928
* else nthPrime(from + 1, to, n)
3029
* }}}
30+
* def secondPrime(from: Int, to: Int) = nthPrime(from, to, 2)
3131
*
3232
* But from a standpoint of performance, the first version is pretty bad; it constructs
3333
* ''all'' prime numbers between `1000` and `10000` in a list, but only ever looks at

0 commit comments

Comments
 (0)