At the beginning, I realized recursion in Joe's "programming Erlang". With the understanding of computing, the experience of recursion will also be different. Here I will record my understanding process.
1. Understand Recursion
Recursion requires the list structure, which is why lisp itself is short for the list processor table. Data is a table, so we can process each element in the table one by one. The processing method is also quite simple:
1. Solve the special situation of empty tables.
2. process the Header element, which is generally a s-expressions (atom or list ).
3. recursively process the tail element. The end element is usually expressed as (CDR lst ).
The above sentence can be more concise:
1. Wipe your ass
2. Processing Header
3. Recursive tail
2. Recursive deconstruct
What languages can achieve recursion?
Obviously, recursive functions must accept list as their parameters (arguments), so they must have a data structure such as list. Second, there must be no effect side data such as first and rest to return the extraction operation.
Let's talk about the function. In fact, the function isNameIn addition, it also indicates the high-level abstraction-he is a processing process. When a function (processing process) accepts the list type, this function is not far from "recursion.
3. Recursive Solution
I remember when I first learned object-oriented, when some people said, "One skill is an object ". You will feel that someone is awesome and immediately worships. However, as time went on, some of them thought it was a tough task. For example, in some applications with many control operations, if you use Oop, you create a bunch of hypothetical objects. This is not just OOP For OOP.
Here, recursion is not suitable for solving all problems. But some problems are actually recursive in nature, such as fast sorting, which is represented by Erlang:
Sort ([bytes | T])->
Sort ([x | x <-t, x <strong]) ++
[Pipeline] ++
Sort ([x | x <-t, x> = bytes]);
Sort ([])-> [].
In terms of task completion:
1. Wipe your ass (empty is returned if list is empty ).
2. Processing header ).
3. Recursive tail (T <distinct and T> = distinct ). In fact, the more common statement here is to deal with the rest, that isLarger than shardAndSmaller than limit.
If we use a natural language, we can use 1st elements as the limit, and then put the elements smaller than the limit in front of the limit, and put the elements larger than the limit in the back of the limit. How do I know if it is bigger than the limit? Recursively go back until there is only one element.
As I said here, recursion is nothing more than an abstract method and a view of the world. Sometimes the world is clear from this perspective, and sometimes it cannot be seen clearly at all. You can try to observe from another angle,Try to be close to the problem domain to solve the problemInstead of the solution domain to solve the problem.