4 ms·
Never forget that cultural differences look odd in either direction. My favorite passage from "Structure and Interpretation of Computer Programs": > One reason
by Syzygies 7y ago
Never forget that cultural differences look odd in either direction. My favorite passage from "Structure and Interpretation of Computer Programs":
> One reason that the distinction between process and procedure may be confusing is that most implementations of common languages (including Ada, Pascal, and C) are designed in such a way that the interpretation of any recursive procedure consumes an amount of memory that grows with the number of procedure calls, even when the process described is, in principle, iterative. As a consequence, these languages can describe iterative processes only by resorting to special-purpose “looping constructs” such as do, repeat, until, for, and while. The implementation of Scheme we shall consider in Chapter 5 does not share this defect. It will execute an iterative process in constant space, even if the iterative process is described by a recursive procedure. An implementation with this property is called tail-recursive. With a tail-recursive implementation, iteration can be expressed using the ordinary procedure call mechanism, so that special iteration constructs are useful only as syntactic sugar.
- Retric 7y agoFrom the other side, tail call recursion is often actually implemented as a loop by the interpreter. Effectively, making many recursive programs just a different way to write a loop.
- madhadron 7y agoUnder the hood it's all conditional jump instructions whether it's tail recursion, loops, or if/else expressions.
- stcredzero 7y agoIs there an alternative to conditional jump instructions? What would a such a computer look like? Maybe such a computer exists, but it's hard for us to see it, because we've been drawn into thinking along Von Neumann machine lines.
- opwieurposiu 7y agoThere other ways to do it, but they tend to be less efficient. https://github.com/xoreaxeaxeax/movfuscator https://github.com/xoreaxeaxeax/movfuscator
- ksherlock 7y agoindexed jump instructions? (where the index is a boolean value corresponding to the if condition...)
- Retric 7y agoSeveral CPU’s had specific loop instructions. These are slow on x86, but where sometimes useful on other CPU’s. Though this is half remembered second hand info, so your mileage may very.
- madhadron 7y agoYou're absolutely right. I'm usually careful about being blinded by current machines. And there are other ways like changing your return stack manually which could be used to loop. I was trying to express that the various mathematical formalisms we think in are all getting translated to the same machine in the end.