3 ms·
The functional language does do away with loops, but when the rubber nets the road, you don’t have any choice: somewhere, something will execute the equivalent
by FrancoisBosun 5y ago
The functional language does do away with loops, but when the rubber nets the road, you don’t have any choice: somewhere, something will execute the equivalent of “for(int i = 0; i <= 10; i++) {}”.
When I implemented Mindcode, I realized that “while” is the basic construct and that all enumerations and looping compiled down into goto.
Mindcode is a Ruby-like language for the Mindustry game. Mindustry has an assembly-like language with a visual editor in-game. Mindcode has a more traditional text-based flow.
- ModernMech 5y ago> somewhere, something will execute the equivalent of “for(int i = 0; i <= 10; i++) Not necessarily; depending on what's going in in the loop, you can compile the code into parallel non-looping instructions that execute on multiple cores or threads. No loops needed.
- throw10920 5y agoThat's a very specific special case. For instance, if you have more iterations than cores or processors, you'll still need to do looping somewhere. In the general case, the statement is still true.
- ModernMech 5y agoIt's a specific case but not a very specific case, and one that is becoming more common as core counts are exploding. And anyway, even if it were a very specific case it's still an existence proof that disproves the assertions that "all that abstraction is being turned into loops and jumps." as one other poster put it. The replies here are speaking in very absolute terms ("you don’t have any choice", "loops and jumps cannot ever go away regardless of the higher level abstractions"), which are not true in an absolute sense. The OP said: > Do you mean for all imperative languages? Functional or declarative languages can do away with loops and jumps And everyone here is answering them so far from the perspective of imperative languages. But depending on the program, it's not necessarily the general case in declarative languages, where we have much more freedom to compile things as we want, including without loops where they would be used in an imperative language. Since this is a thread about language design and we're talking about alternative paradigms and how things get compiled to instructions, it's absolutely true that if our problem can be parallelized we don't have to loop at all. This is not a special case, but something that is generally applicable to many kinds of situations. Now that we're entering a world of potentially 1000s of cores available on consumer CPUs in the near future, what I'm saying is going to become the general case more and more.
- jstimpfle 5y agoIf the iteration bounds are statically known (i.e. 0...10 in above example) you can avoid the loop by unrolling it, or using some kind of explicit parallelism, like SIMD for example. In general, the iteration bounds aren't known and some kind of loop is required.