corrected spelling of 'optimization' (#32755)
This commit is contained in:
@ -66,9 +66,9 @@ You might be wondering why you would use `loop/recur` rather than simply definin
|
||||
|
||||
This is more concise, and works in a similar way. Why would you _ever_ use loop and recur?
|
||||
|
||||
### Tail Call Optimisation
|
||||
### Tail Call Optimization
|
||||
|
||||
If you use `loop/recur`, then the compiler (the software that turns Clojure code into JVM bytecode) knows that you want to create a recursive loop. This means that it tries its hardest to optimise your code for recursion. Let's compare the speed of `fact` and `fact-no-loop`:
|
||||
If you use `loop/recur`, then the compiler (the software that turns Clojure code into JVM bytecode) knows that you want to create a recursive loop. This means that it tries its hardest to optimize your code for recursion. Let's compare the speed of `fact` and `fact-no-loop`:
|
||||
|
||||
(time (fact 20))
|
||||
; => "Elapsed time: 0.083927 msecs"
|
||||
@ -79,11 +79,11 @@ If you use `loop/recur`, then the compiler (the software that turns Clojure code
|
||||
|
||||
 <a href='https://ideone.com/tpC0Xo' target='_blank' rel='nofollow'>IDEOne it!</a>
|
||||
|
||||
At this scale, the difference is negligible. In fact, `fact-no-loop` is occasionally faster than `fact` due to the unpredictable nature of computer memory. However, on a larger scale, this kind of optimisation can make your code much, much quicker.
|
||||
At this scale, the difference is negligible. In fact, `fact-no-loop` is occasionally faster than `fact` due to the unpredictable nature of computer memory. However, on a larger scale, this kind of optimization can make your code much, much quicker.
|
||||
|
||||
### Nesting Recursion Within functions
|
||||
|
||||
`fact-no-loop` works without `loop/recur` because the entire function is recursive. What if we wanted part of our function to use a recursive loop, and then the rest of it to do something non-recursive? We'd have to define two entirely separate functions. Using `loop/recur` lets us use a little anonymous function instead.
|
||||
|
||||
| [ Previous](//forum.freecodecamp.com/t/clojure-create-local-variables-with-let/18415) | [ Home ](//forum.freecodecamp.com/t/clojure-resources/18422) | Next |
|
||||
| [Let Bindings](//forum.freecodecamp.com/t/clojure-create-local-variables-with-let/18415) | [Table of Contents](//forum.freecodecamp.com/t/clojure-resources/18422) | To Be Added |
|
||||
| [Let Bindings](//forum.freecodecamp.com/t/clojure-create-local-variables-with-let/18415) | [Table of Contents](//forum.freecodecamp.com/t/clojure-resources/18422) | To Be Added |
|
||||
|
Reference in New Issue
Block a user