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.

Traversing nested data-structures in various languages

136 pointsby selfabout 4 years ago

11 comments

11235813213455about 4 years ago
Just wanting to say that all JS solutions are quite &#x27;bad&#x27;, except the simple for-of, because they&#x27;re combining pure array methods (.map, .reduce) and side-effects (external variable to that method), not even talking about modifying Array protoype <a href="https:&#x2F;&#x2F;github.com&#x2F;josevalim&#x2F;nested-data-structure-traversal&#x2F;blob&#x2F;master&#x2F;javascript&#x2F;map_with_state.js#L3" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;josevalim&#x2F;nested-data-structure-traversal...</a>, never do this, don&#x27;t touch to objects you don&#x27;t own, and that others would access and not expect to be modified!<p>I&#x27;ll make a PR to try to contribute, instead of just complaining like that, hehe<p>Btw I&#x27;m surprised the structure isn&#x27;t deeply nested (requiring recursion to process it), it&#x27;d be more interesting
评论 #26779363 未加载
ghufran_syedabout 4 years ago
Interesting how different some of the approaches are in the <i>same</i> language, never mind different languages. In clojure, the “atom” version is 5 lines (not including data or tests), while the “zipper” version is 47 lines and the “reduce” version is 31 lines
评论 #26778764 未加载
评论 #26786173 未加载
评论 #26785815 未加载
评论 #26778029 未加载
Hurtakabout 4 years ago
The whole problem seems to be bizarrely defined when it comes to data structures.<p>Basically the input is `data+config` merged into one object and the return value is `data+config+tranversal_properties` merged into one object with lots of solutions mutating the original input data.
评论 #26786103 未加载
fermigierabout 4 years ago
What are the OP&#x27;s conclusion from this experiment ?<p>I was expecting the FP languages solutions to be exceptionally short and elegant, but after a quick glance it seems to me that the Python and Python-like languages (e.g. Nim, Zig, etc.) are &quot;winning&quot; (YMMV of course).
评论 #26777737 未加载
评论 #26777763 未加载
评论 #26778026 未加载
评论 #26777987 未加载
评论 #26779715 未加载
buro9about 4 years ago
Why do I see things like this and still think that XML and XSLT made a lot of this stuff very simple and portable and that we lost a good bit of progress by choosing JSON, YAML, etc after we already had great validation of schemas, translation, streaming and DOM parsing, etc.
评论 #26777556 未加载
评论 #26777258 未加载
评论 #26777814 未加载
评论 #26780609 未加载
评论 #26777699 未加载
评论 #26777318 未加载
raspasovabout 4 years ago
Non-idiomatic ClojureScript, 10 lines:<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;raspasov&#x2F;0521706c3f963a9209152bfb2becd91c" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;raspasov&#x2F;0521706c3f963a9209152bfb2be...</a><p>IMO The problem is poorly defined. Data structures should avoid control flow instructions like &quot;reset_lesson_position&quot;
评论 #26778136 未加载
leontrolskiabout 4 years ago
In python&#x2F;javascript, I&#x27;m a big fan of using yield - <a href="https:&#x2F;&#x2F;leontrolski.github.io&#x2F;recursing-with-yield.html" rel="nofollow">https:&#x2F;&#x2F;leontrolski.github.io&#x2F;recursing-with-yield.html</a><p>It just <i>feels</i> nice to me.
评论 #26779650 未加载
citrin_ruabout 4 years ago
TIL about postfix dereference in Perl: <a href="https:&#x2F;&#x2F;perldoc.perl.org&#x2F;perlref#Postfix-Dereference-Syntax" rel="nofollow">https:&#x2F;&#x2F;perldoc.perl.org&#x2F;perlref#Postfix-Dereference-Syntax</a><p>One of advantages of Perl to me stable syntax - usually I can open code written by someone nowadays after not using Perl and not encounter any unknown language features. Turned out even in Perl there are new features you need to learn first before you can read the code, though compare to other languages it still easy to keep up with all new features.
jedisct1about 4 years ago
The Rust and Haskell versions are complicated to understand for such a simple task.
评论 #26779722 未加载
评论 #26780489 未加载
评论 #26779280 未加载
taericabout 4 years ago
The common lisp solutions should include at least one LOOP example. Since that would almost certainly be directly comparable to the python example.
评论 #26788917 未加载
marvel_boyabout 4 years ago
Simplicity wins. Zig wins again. One more time.
评论 #26778934 未加载