Skip to content

Commit

Permalink
rename blog post loop to loop-and-recur
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed May 19, 2024
1 parent 403f81f commit af83123
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions content/blog/loop.md → content/blog/loop-and-recur.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
+++
title = "Loop"
title = "Loop and recur"
date = "2024-05-18"
+++

Many functional programming models prefer to express repetition by recursive function calls.
Many functional programming models prefer to express repetition by **recursive** function calls.

In Phel's iteration process, there is a highly functional and convenient `for` macro, but there is also a `loop` special form that performs more primitive loop processing.

Expand Down Expand Up @@ -36,12 +36,14 @@ When calling as recursion, the `loop` format specifies `recur`, but the recursiv
For everything else, you can see that you can use `loop` to write iterations in the same way you would write recursive functions.

However, there is one more thing to keep in mind.
The recursive structure of `loop` must be tail recursive.
The recursive structure of `loop` must be _**tail recursive**_.
This means that `recur` can only be placed at the location where it is evaluated last in the iteration process within `loop`.
If you try to place `recur` in any other location, the following error will be displayed.
If you try to place `recur` in any other location, the following error will be displayed:

```
ERROR: Can't call 'recur here
```

If this error is displayed, please check whether the recursive structure of `loop` is tail recursive.

> Note: _**Tail recursion** is a recursive function where the recursive call is the final action in the function. This means the function has nothing else to do after the recursive call, which makes it possible for the compiler or interpreter to optimize the function by transforming it into a loop._

0 comments on commit af83123

Please sign in to comment.