/canonical/archive/2007/12/05/
Continuation is one of the ways to solve the state problem. Simply put, there is a state when there is time: the past, present and future. For the past, we have history, and we will decide what happened now because of what happened in the past. For example, because we drank high wine yesterday, we can only eat porridge today; and now is yesterday tomorrow, so we must record today's status for what we can do tomorrow, for example, we have eaten porridge today; as for tomorrow, of course, there are many things to happen, and we have to prepare one by one.
Oh, what is important is this "be prepared". This is called: Event in a computer system. It is called a plan or a sudden outbreak. Do you know why our PC can run? En... is because there is an instruction pipeline that executes the instruction according to a small enough time slice. For the computing system, the instruction access behavior that occurs at this timing is interrupt. So one day a friend asked me: If the execution logic only has order, branch and loop, then what are the triggers in the process system? I thought about it for a long time, but there was no solution. Now to answer this question, we have to add the dimension of "time". The so-called bursts, concurrency and similar things are logic under the concept of time sequence.
OK, when we are "prepared" and prepare for something in the future - simply put, it is just a clock handler (in Windows, it is called OnTimer, in browsers, it is called setTimeout/setInterval). In order to make a meal of spaghetti in a functional language at this time, we explain: "We are ready", and "how are we ready". According to the basic principle of functional formula, a function is state-free and has nothing to do with a timing such as "future". This has become a contradiction.
In fact, we have already conflicted with this contradiction head-on at the beginning, and this is the "cycle". Because the loop requires a state quantity to indicate the loop progress,
This "progress" is timing-related. The functional method uses "recursion" to solve it, that is, pass this progress through the parameters of the recursive function. On both sides of the "recursive parameter" - the functional formula is time-dependent. The problem brought about by this is stack overflow, and the solution is tail recursion; the problem brought about by this is programming complexity, and whether it can be proved that tail recursion can replace all recursion; the solution is... Weinberg is right, all solutions to the problem will bring new problems. Oh...It's Weinberg again. Now, we need "more states" clearly because we have already run the system in one or more timings - that is, the CPU. Even if we have nodes and are guaranteed to be "no wormholes", we also need to solve the problems of the past, present and future in a CPU.
Functional immortals said two words: Continue. It's simple, it means passing the past, present state, and future preparation as parameters. It seems that the "now" will explode immediately, because it must include both past, present state and changes, as well as future operations. So the new solution is: if you want to not explode now, just don't perform operations on the "continuous" interface.
The operation is made by the "future" based on the "past" data, which is continuous. The functional feature that supports it is lazy evaluation. Simply put,
function f(x, c) {
...
c(x);
}
f(data, f);
Since c itself does not evaluate on the transmission interface f(), the explosion will occur when/will not occur when c(x) performs operations in the future. if
The entropy of the universe has a limit, so this limit is also in the last known future. Moreover, in the last known future, it is possible to return to the present. This is
Two principles of sustainability:
--------------------
After a successful continuation, a new continuation (or process)
A failure continues to return to the previous selection point
--------------------
It is precisely because there is a state of continuous, and this state and the state themselves are passed through function parameters, so "return to the selection point" just comes from the body.
A decision of , has nothing to do with the current state.
7. More advanced functional formulas (2)
In any case, the complexity of various functional forms does exist by maintaining a self-purity in the programming paradigm. For example, generator (generator)
In this problem, since there is a relationship between the generation of a batch of data (such as increments), the generation process is time-series-related (not always in a call).
Get all the data), so the functional language defines a function concept like "generator". We can define a yield in the generator,
This return is a wormhole that returns to this "now" in the future. Through this wormhole, we can get a time-related data. under
This is an example (an example of Fibonacci sequence on mozilla):
<!-- for firefox 3 -->
<script type="application/javascript;version=1.7">
function fib() {
var i = 0, j = 1;
while (true) {
yield i; //<-The wormhole is here
var t = i;
i = j;
j += t;
}
}
var g = fib();
a = ();
b = ();
c = ();
// ...
// .. Three days later (or a cycle), a certain time and space traveler wants to go back to the fib to check it out
z = ();
// Oh, it turns out to be worth "2"
alert(z);
</script>
8. Conclusion
It seems that this article "No Nonsense" has a lot of nonsense... Haha, joking, it's really no nonsense, is it a living person who can read it?
If you really want to study so much, you should go to university textbooks. Or, here is a book called "The Essence of JavaScirpt Language and Programming Practice".
Seeing wood, the essence of language...haha.