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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Specter – Clojure API for immutable programming (2017)

152 点作者 amgreg超过 4 年前

12 条评论

tekacs超过 4 年前
Specter is tremendously useful and rarely lets on a case where it can’t perform a transformation. For ensuring that you’re getting the most efficient form of a transformation [0] it’s incredible —- and it is somewhat data-oriented, allowing easy saving and reuse of navigators.<p>Meander [1] is also wonderful. Its unification-based approach makes for nice expressions of intent. Its strategy-based approach to rewriting [2] is more flexible than most common walker libraries, too.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;redplanetlabs&#x2F;specter&#x2F;wiki&#x2F;Specter&#x27;s-inline-caching-implementation" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;redplanetlabs&#x2F;specter&#x2F;wiki&#x2F;Specter&#x27;s-inli...</a><p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;noprompt&#x2F;meander" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;noprompt&#x2F;meander</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;noprompt&#x2F;meander&#x2F;blob&#x2F;epsilon&#x2F;doc&#x2F;strategies.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;noprompt&#x2F;meander&#x2F;blob&#x2F;epsilon&#x2F;doc&#x2F;strateg...</a>
评论 #24379361 未加载
john-shaffer超过 4 年前
Specter is fantastic. It makes transformations on deeply nested data structures easy. Want to transform all the &quot;datetimes&quot; from JSON data into <i>actual</i> datetimes (or vice versa)? It takes about five minutes if you have to look everything up. Works with ClojureScript too.<p>Some production code:<p><pre><code> (defn transform-tagged-values [x] (sp&#x2F;transform (sp&#x2F;walker tr&#x2F;tagged-value?) tagged-value-&gt;cljs x)) </code></pre> Give it a predicate for which values to transform, and a function to do the transformation. Couldn&#x27;t be easier.
评论 #24377371 未加载
boxed超过 4 年前
I invented instar (<a href="https:&#x2F;&#x2F;github.com&#x2F;boxed&#x2F;Instar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;boxed&#x2F;Instar</a>) which is quite similar to specter (imo a little bit nicer) because I also thought the built in API was weirdly clunky in these respects.
评论 #24379443 未加载
评论 #24377293 未加载
评论 #24377682 未加载
setzer22超过 4 年前
Specter is always on my clojure toolbox. Not only it makes transforming arbitrarily nested data painless, it also is usually more efficient than the average hand-rolled code!<p>A great example of why macros in Lisp are powerful, and how they empower you as a user even if you never write one.
jdc超过 4 年前
Previous discussion of Specter: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10295060" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10295060</a><p>also cf<p>Glom for Python: <a href="https:&#x2F;&#x2F;sedimental.org&#x2F;glom_restructured_data.html" rel="nofollow">https:&#x2F;&#x2F;sedimental.org&#x2F;glom_restructured_data.html</a><p>Hashdig in Ruby&#x27;s standard library: <a href="https:&#x2F;&#x2F;ruby-doc.org&#x2F;core-2.7.1&#x2F;Hash.html#method-i-dig" rel="nofollow">https:&#x2F;&#x2F;ruby-doc.org&#x2F;core-2.7.1&#x2F;Hash.html#method-i-dig</a>
cutler超过 4 年前
So it turns out that Clojure is the ultimate data-wrangling tool yet there&#x27;s no chance of earning a living with it. So much for innovation. Technology is a strange industry where conservative Java bondage and a 2-bit browser scripting extension with no stdlib reign supreme.
评论 #24381291 未加载
评论 #24380757 未加载
评论 #24381115 未加载
评论 #24380993 未加载
mrbonner超过 4 年前
Darn! This is sleek!<p>I have been learning Clojure off and on for almost a year now. I gotta say that it has changed my mind to a &quot;Aha, I got lisp now&quot; moment. Working with it is a joy, especially it integrates so well with the JVM and all available Java libraries out there.<p>I can&#x27;t believe I have missed Specter during my learning journey. How could I not find out about this soon enough. I mostly deal with static typed languages and seeing the primary use of map and keywords as main data structure scares me. Rich Hicky said not to put too much emphasis in what in the map but the data&#x2F;keywords you need, kind of like you do not care what in the UPS truck as long as it could deliver your package, right? But, navigating maps and nested data structures around is the pain. Specter definitely easies that pain a lot now that I know it!<p>This is why I am grateful for hackernews. Once in awhile, browsing the site and discover something like this makes me rethink the ways I do stuff. It also reminds me that I could be missing a lots of similar goodies on my way learning Clojure. I am prepared to have me mind blown again!!!
slifin超过 4 年前
There&#x27;s a lot of alternatives in this space<p>Meander was the last one I can remember:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=9fhnJpCgtUw" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=9fhnJpCgtUw</a>
评论 #24375838 未加载
sova超过 4 年前
Like SQL for nested maps in Clojureland. Neat. The DSL [ALL :a even?] does feel a tiny bit un-clojurey to me as well, maybe making it look like [:all :a even?] would make it clearer.
评论 #24377992 未加载
评论 #24376779 未加载
评论 #24377726 未加载
dimovich超过 4 年前
Specter is really handy for manipulating data structures, and have been happily using it.<p>I wonder, is it possible to select some subset of a map? Say you have these paths:<p>(def paths [[:some :path] [:another :deeper :path] [:yet :another :one] [:yet :another :one :deeper]])<p>And select from a map these paths. You could do it with get-in, but maybe Specter can do it faster? I couldn&#x27;t find a way to do it with Specter...
dwohnitmok超过 4 年前
I hope that more and more lens implementations should catch on in languages with immutable data structures.<p>They really are the key to make immutable data structures as easy to update and work with as mutable data structures.
kazinator超过 4 年前
TXR Lisp:<p><pre><code> This is the TXR Lisp interactive listener of TXR 243. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. </code></pre> Give me all the .c files:<p><pre><code> 1&gt; (glob &quot;*.c&quot;) (&quot;abcd.c&quot; &quot;args.c&quot; &quot;arith.c&quot; &quot;buf.c&quot; &quot;cadr.c&quot; &quot;chksum.c&quot; &quot;combi.c&quot; &quot;crazyffi.c&quot; &quot;debug.c&quot; &quot;dict.c&quot; &quot;eval.c&quot; &quot;ffi.c&quot; &quot;filter.c&quot; &quot;ftw.c&quot; &quot;gc.c&quot; &quot;glob.c&quot; &quot;halfsip.c&quot; &quot;hash.c&quot; &quot;highest-bit-main.c&quot; &quot;highest-bit.c&quot; &quot;highest-test.c&quot; &quot;isqrt.c&quot; &quot;itypes.c&quot; &quot;lex.yy.c&quot; &quot;lib.c&quot; &quot;lisplib.c&quot; &quot;match.c&quot; &quot;parser.c&quot; &quot;protsym.c&quot; &quot;query.c&quot; &quot;rand.c&quot; &quot;regex.c&quot; &quot;signal.c&quot; &quot;socket.c&quot; &quot;stream.c&quot; &quot;struct.c&quot; &quot;strudel.c&quot; &quot;sysif.c&quot; &quot;syslog.c&quot; &quot;termios.c&quot; &quot;test.c&quot; &quot;tree.c&quot; &quot;txr.c&quot; &quot;unwind.c&quot; &quot;utf8.c&quot; &quot;vecho.c&quot; &quot;vm.c&quot; &quot;y.tab.c&quot;) </code></pre> OK, which ones are over 100000 bytes:<p><pre><code> 2&gt; (keep-if [chain stat .size (op &lt; 100000)] (glob &quot;*.c&quot;)) (&quot;arith.c&quot; &quot;eval.c&quot; &quot;ffi.c&quot; &quot;lex.yy.c&quot; &quot;lib.c&quot; &quot;match.c&quot; &quot;stream.c&quot; &quot;y.tab.c&quot;)</code></pre>
评论 #24380272 未加载