World Playground Deceit.net Blog New Posts 2025 05 Novel review: S.M. Stirling - Under the Yoke (1989) The novel The ideas 04 Music review: Deathspell Omega - Si Monvmentvm Reqvires, Circvmspice (2004) Ogg Vorbis cover art embedding: Tcl vs Common Lisp In Tcl In Common Lisp In MY Common Lisp Adding keyword parameters to Tcl procs How it's made Movie review: Ford v Ferrari (2019) Music review: Dead Can Dance - Within the Realm of a Dying Sun (1987) Music review: Dark Tranquility - Skydancer (1993) 03 Music review: Darkthrone - Goatlord (1996) Music review: Danzig - Danzig II - Lucifuge (1990) Music review: Crowbar - Crowbar (1993) Speeding up cljqalbum Pruning Portage package config files Music review: Comus - First Utterance (1971) Movie review: Idiocracy (2006) A Common Lisp jq replacement Music review: Cocteau Twins - Heaven or Las Vegas (1990) 02 Music review: Blut Aus Nord - Ultima Thulée (1995) Music questions challenge What are five of your favorite albums? What are five of your favorite songs? Favorite instrument(s)? What song or album are you currently listening to? Do you listen to the radio? If so, how often? How often do you listen to music? How often do you discover music? And how do you discover music? What's a song or album that you enjoy that you wish had more recognition? What's your favorite song of all time? Has your taste in music evolved over the years? Music review: 椎名林檎 (Shiina Ringo) - 勝訴ストリップ (Shōso Strip) (2000) Linux pipe(2) vs ring buffer Novel review: Robert Heinlein - The Moon is a Harsh Mistress (1966) Music review: Black Flag - My War (1984) 01 Music review: Belkètre - Ambre Zuèrkl Vuorhdrévarvtre (1996) Cooking recipe: bœuf bourguignon Most memorable extreme music screaming Music review: Amesoeurs - Ruines Humaines (2006) Novel review: Terry Pratchett - Mort (1987) Novel review: Mark Danielewski - House of Leaves (2000) PDF to CBZ for e-reader Music review: Acid Bath - Paegan Terrorism Tactics (1996) Video game review: Bloodstained: Ritual of the Night (2019) Dotfiles management 2024 12 Novel Review: Liu Cixin - The Three-Body Problem (2008) GNU parallel out, pararun in Advent of Code 2024: retrospective Advent of Code 2024: Day 01 11 How I Learned to Stop Worrying and Love GC Initial C weenie stance Insights and updated views New stance See also Music review: Thee Maldoror Kollective - New Era Viral Order (Dogma Slaughterhouse and the Children of Anaemia) (2002) Novel review: Terry Pratchett - Guards! Guards! (1989) & Men at Arms (1993) Smuggling files under Google's nose First blood: nested zips Second skirmish: file signature doctoring Final setback and victory My archives Emacs: separate minibuffer history for a command Music review: Techno Animal - The Brotherhood of the Bomb (2001) CL iterate's COLLECT performance notice 10 Music review: Burzum - Det som engang var (1993) QoL addition to Common Lisp :start/:end Closures in Tcl What kind of closures In Tcl Music review: Abigor - Supreme Immortal Art (1998) git secret filter My sfeed setup Introduction Sfeed praise Personal additions Why I like Tcl Pros Cons Conclusion 09 Music review: Samael - Eternal (1999) Movie review: The Crow (1994) Bourne shell stdio trivia while read loops and interactive commands Default stream buffering Tags fantasy (1) advent of code (2) alternate history (1) black metal (6) blackgaze (1) comedy (3) computer science (1) cooking recipe (1) darkwave (1) dotfiles (5) emacs (1) fantasy (1) folk (1) gentoo (1) git (1) gothic metal (1) hacking (1) heavy metal (1) hip hop (1) horror (1) image processing (1) industrial metal (1) j-rock (1) lisp (5) melodic death metal (1) movie review (3) music review (19) music (1) novel review (6) performance (3) personal (2) post-punk (1) programming (15) punk (1) science fiction (2) sh (4) sludge metal (1) stoner metal (1) tcl (4) video game review (1) About Me Website Raison d'être Design choices Links Webrings Lainring Code

一个用 Common Lisp 写的 jq 替代品

发布于 2025-03-06 标签: lisp, programming 标题说明了一切,我非常不喜欢 jq 复杂、难以记忆的 ad hoc DSL,它瞬间加入了 CMake 和 gnuplot 的行列,占据了我内心的痛苦之地。它真的应该是一个库,并用一个广为人知的脚本语言(比如 Python)的 eval 函数做一个 CLI 包装器。

而且我不是唯一一个抱怨这个问题的人,但它就是占领了市场份额,因此在任何软件包仓库中都很容易找到(有时甚至预装),并且在网络上拥有最多的复制粘贴素材。它之所以胜出,原因很常见:当时缺乏强大的竞争对手,有足够的灵活性来通过足够的痛苦和努力来管理大多数任务,以及现在的惯性。

但是,我已经达到了我的“受够了!”的地步,并决定像 VapourSynthwaf 那样,用我所知道和喜爱的语言:CL 来替换它。

目前,cljq 只是一个非常简陋的管道,它将 JSON(argv 或 stdin)解析为一个变量 $, 用 eval 执行任意 CL 形式,并将结果序列化到 stdout(使用 [jzon](https://world-playground-deceit.net/blog/2025/03/https:/github.com/Zulu-Inuoe/jzon))。但在我看来,受 JSONPath 启发的查询运算符 ? 已经是一种改进:

$ json='{"root": {"a": [0, 1], "b": [2, 3]}}'
$ echo "$json" | jq '.root | map(.[1])'
[
 1,
 3
]
$ echo "$json" | cljq '(? $ "root" * 1)'
[
 1,
 3
]

这是一个 JSONPath <=> ? 的小对照表(使用上述 RFC 中的一些示例):

JSONPath| cljq 的 ? ---|--- $.store.book[*].author| (? $ "store" "book" * "author") $..author| (? $ ** "author") $.store.*| (? $ "store" *) `$.store..price