TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Programming languages should have a tree traversal primitive

12 点作者 TylerGlaiel25 天前

1 comment

hyperhello25 天前
This is interesting, but the syntax doesn&#x27;t seem to have the right expressiveness for such a large change.<p><pre><code> for recursive (Node t = tree.root; t != NULL;) { puts(t.value); if (t.value == target) break; if (t.value == dontfollow) continue; if (t.left) continue t.left; if (t.right) continue t.right; } return t; </code></pre> Regular &#x27;break&#x27; is to really break out of the structure like a regular for, as regular &#x27;continue&#x27; is to do the next iteration. But if continue has a value to recurse on, it reenters the for loop like a subroutine.<p>As a bonus, I think this is tail-call-optimization friendly.
评论 #43837285 未加载