Skip to content

Commit

Permalink
Start describing "easy" case
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Nov 20, 2023
1 parent 98b4c41 commit 30a506f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pages/adt-interpreters/tail-recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,10 @@ object Expression {
```
</div>

**TODO: complete this discussion of simplified CPS**

### When Tail Recursion is Easy

Doing a full CPS conversion can be quite involved. Some methods can made tail recursive or stack safe without requiring full CPS.
Doing a full CPS conversion and trampoline can be quite involved. Some methods can made tail recursive without so large a change.
Remember these examples we looked at earlier?

```scala mdoc:reset-object:silent
Expand All @@ -710,7 +710,9 @@ def isTailRecursive(count: Int): Int = {
}
```

Both methods calculate the sum of natural numbers from 0 to `count`. Let's us substitution to show how the stack is used by each method, for a small value of `count`.
The tail recursive version doesn't seem to involve the complexity of CPS. How can we relate this to what we've just learned, and when can we avoid the work of CPS and trampolining?

Let's use substitution to show how the stack is used by each method, for a small value of `count`.

```scala
isntTailRecursive(2)
Expand Down

0 comments on commit 30a506f

Please sign in to comment.