TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python to Scheme to Assembly (2014)

127 pointsby sea6earabout 10 years ago

10 comments

emmanueloga_about 10 years ago
I gather than the author is being hyperbolic in order to emphasize his point (&quot;is easier to reason about correctness with recursion&quot;). But the reason recursion doesn&#x27;t &quot;suck&quot; in python (an other languages without TCE), even with a small call stack, is that usually it is used to tackle problems with a divide-and-conquer strategy. Even if you are handling a massive amount of items, if your recursive calls splits them to handle in two or more parts until there&#x27;s no more to handle, then it is very hard to deplete the call stack:<p>log2 1_000_000_000_000_000 =&gt; 49.82892142331043<p>&quot;Recursion and iteration are equally expressive: recursion can be replaced by iteration with an explicit stack, while iteration can be replaced with tail recursion. Which approach is preferable depends on the problem under consideration and the language used.&quot; [1]<p>BTW, I sympathize with the author&#x27;s thesis. I was trying to remember algorithms that are easier to reason about in their iterative form... but I can&#x27;t remember any. Conversely, compare recursive vs iterative DFS [2].<p>1: <a href="http://en.wikipedia.org/wiki/Recursion_(computer_science)" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Recursion_(computer_science)</a><p>2: <a href="http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_2" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tree_traversal#Depth-first_2</a>
评论 #9256107 未加载
rpedrosoabout 10 years ago
This article really got me in the mood to play around with Racket again.<p>Incidentally, I find it hard to square with Guido&#x27;s belief that recursion isn&#x27;t the basis of all programming. Sure, Python has some powerful iterators, but my CS professors made it clear that iteration is basically just a special case of recursion.<p>It might very well be the right decision for Python to prefer iteration, but to deny the role of recursion in computer science altogether seems misguided.
评论 #9254187 未加载
评论 #9254043 未加载
评论 #9264513 未加载
评论 #9255190 未加载
评论 #9255251 未加载
评论 #9254145 未加载
tiffanyhabout 10 years ago
This is also one of many reasons why people love Lua.<p>Lua does proper tail recursion automatically.<p><a href="http://www.lua.org/pil/6.3.html" rel="nofollow">http:&#x2F;&#x2F;www.lua.org&#x2F;pil&#x2F;6.3.html</a>
Cyberisabout 10 years ago
This was a great article. I&#x27;ve spent the last year filling in gaps in my own CS background including CL, Scheme, Racket, CISP, HtDP, etc. This is the first time I&#x27;ve seen good solid reasoning about Scheme using Assembly and it makes things really clear. I wish the author would have taken a little more time reasoning to the correctness of recursion using the y combinator. That&#x27;s what he ended up with but it would have been helpful to break that down a bit more. Also, he mentioned that his next article in that series would have covered continuations (specifically call-with-current-continuation) and I REALLY would have enjoyed that since I find continuations a little hard to grasp.
评论 #9254833 未加载
hawkiceabout 10 years ago
If your goal is to reason about correctness, recursion can be a useful tool. Assembly... is not the hammer I&#x27;d bust out for that particular reasoning task.
srikuabout 10 years ago
It would&#x27;ve been nice if mathematical induction were indicated as the foundation of recursion. You&#x27;re not assuming &quot;it does the right thing&quot; and then proving &quot;it does the right thing&quot;. What you&#x27;re doing is that you&#x27;re proving that &quot;it does the right thing&quot; by showing that &quot;it does the right thing for N&quot; if &quot;it does the right thing for N-1&quot;, and your terminal condition is something like &quot;it does the right thing for 0&quot;. Thus mathematical induction takes care of both correctness and termination.
golergkaabout 10 years ago
&gt; is easier to reason about correctness<p>&gt; my favorite programming language is x64 assembly<p>So, author is _really_ used to reading asm and also smarter than an average developer (and yours truly) or doesn&#x27;t really care about being able to reason that much.<p>(But let me be clear, I&#x27;m not being sarcastic and wouldn&#x27;t be surprised if he&#x27;s really 10x genius.)
评论 #9256772 未加载
评论 #9257100 未加载
peter_l_downsabout 10 years ago
Great article. Fun to read about both Scheme and Assembly at the same time since I&#x27;m currently taking class on each (6.004, 6.945 @ MIT). It&#x27;s great to get theory from both ends of the abstraction spectrum.
Veedracabout 10 years ago
I don&#x27;t get the argument about why loop invariants are any more complicated than tail calls. The link doesn&#x27;t seem to clear it up (the same problem would occur with the direct translation to tail recursion).
baldfatabout 10 years ago
BASIC --&gt; Assembly ---&gt;&gt; Fortran -----&gt; C+- ----&gt; SQL<p>Now I mostly use R and SQL
评论 #9254432 未加载