编程与软件工程calculist.org
同像性并不是重点(2012)
Homoiconicity isn’t the point (2012)
2018 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇 2012 年的博文认为,Lisp 常被称道的“同像性”(代码即数据)并非其真正的关键所在;真正重要的是 Lisp 语法无需解析即可读取,以及宏系统让语言可以自我变换。文章多次登上 HN 首页,引发了关于语法、宏与语言设计本质的持续讨论。
为什么经久不衰:它触及了 Lisp 社区几十年来争论的核心——括号、宏与同像性到底哪个才是本质,每次重提都能激发新的语言设计思考。
HN 评论精选
括号之争偏离了 Lisp 的本质,宏也只是补丁,理想语言应以操纵语言为核心能力。
处理括号仍然是解析,只是幼儿园级别的解析。我写过数千行经过预处理的 Scheme 代码来消除大部分括号,我确信 Lisp 是在括号问题上打了一场错误的最后防线,这远非 Lisp 的重点。有了现代编辑器的语言服务器支持和语法着色,语言可以随意变换外观而不影响语义。Lisp 虽然比任何语言都更容易自我修改,但宏只是附加物;我更希望看到一门以操纵语言本身为核心能力、数据结构的便利只是随之而来的语言。
Syzygies查看英文原文
Processing parentheses is still parsing. It's kindergarten-level parsing, but it's still parsing. I've written thousands of lines of scheme code preprocessed to eliminate most parenthesis. I'm convinced Lisp self-asphyxiated by fighting a last stand on parentheses, which is so far from the point of Lisp. With modern editor "language server" support and syntax coloring, languages can shape-shift to any appearance they want, separate from meaning. While I love the poetic look of parenthesis-spare Lisp, Bill Joy got it right when he said that code density on a screen affects programmer productivity. I love Haskell, both for this and because one reasons about the activity of programming as if one is doing algebra. While Lisp more easily modifies itself than any other language, macros are bolted on. No one can tell me with a straight face that with a thousand runs of the civilization simulation, our Lisp macros would be the best run. I'd love to see a language where manipulating the language is the core strength, and all ease with data structures follows as a consequence. Lisp is not that language; peek into some of the other simulation runs.
同像性的核心正是“无需解析即可读取代码”这一点。
“Lisp 语法的强大之处不在于它能表示为数据结构,而在于它可以无需解析就被读取。”对我来说这一直就是同像性的全部意义所在。
k__查看英文原文
"What makes Lisp’s syntax powerful is not the fact that it can be represented as a data structure, it’s that it’s possible to read it without </em>parsing</em>." For me that always was exactly was homoiconicity was all about.
免解析的语法带来一种把代码当作数据来阅读和变换的思维方式。
这比我预想的更微妙。对我来说,不必在脑中费力解析代码,会解锁一种阅读代码的心智模式——代码真的可以被看作一个列表,我也更容易看到变换代码的方式。当然,我其实很喜欢 LOOP 和 FORMAT,它们虽然破坏了易解析性,但常常作为连贯的代码单元独立运作。
taeric查看英文原文
This was what turned out to be more of a subtle point than I thought it would be in https://taeric.github.io/CodeAsData.html For me, there is a mindset of how to read the code that is unlocked by not having to specially parse so much of it in my head. It really can be seen as a list of code. And I can more easily see ways of transforming the code. Granted... I actually like the LOOP and FORMAT forms a lot. They somewhat break the easy to parse, but often they work as a coherent unit of code by themselves.
真实案例说明:需要复杂解析的语言会让代码分析工具极其脆弱,免解析格式价值巨大。
即使不用宏,语言拥有“无需解析即可读取”的格式也很有用,因为新版本语言可能引入破坏现有工具的关键字。我经历过的最糟情况是对 Haskell 代码做静态分析:LambdaCase 等可选特性会改变文件的解析方式,导致解析库失效,只能直接用 GHC 编译器;而 GHC 的 API 难用且常崩溃,最终我不得不重新实现 Cabal 和 GHC 的命令行调用。
chriswarbo查看英文原文
Even without macros, it's useful for languages to have a format that's "readable without parsing", since new language versions can introduce keywords that break existing tooling. The worst case I experienced was a project to perform static analysis on Haskell code. Some optional features (e.g. LambdaCase) alter the way files must be parsed, and I recall at least one causing an ambiguity. This made parser libraries pretty useless, so I had to use the GHC compiler directly. This was around 2015, when GHC's API was much harder to use programatically; in particular it would often crash (saying "the impossible happened") if it wasn't given exactly the right "DynFlags". Those were hard to guess, so had to be passed through as commandline arguments, essentially re-creating the GHC command! Sometimes those features and flags are toggled in a "pragma" comment at the top of a file, but it is also very common for projects to specify these in a separate config file for the Cabal build system. Those files are a non-standard format, so we have to parse them using the Cabal library. Hence I ended up essentially re-implementing the Cabal command, as a way to pass the right arguments to my re-implemented GHC command. That still struggled to parse Haskell code, due to widespread use of the C preprocessor (CPP). I ended up using the vanilla GHC and Cabal commands, but added my own optimisation pass as a GHC plugin. This pass is a function accepting and returning "GHC Core" (one of GHC's intermediate representations); the only side-effects it permits are for error reporting. Hence my pass just returned its input unmodified, whilst also printing it to stderr (as s-expressions, for simplicity). This "GHC Core" representation was usable for my project, but I still find it incredible that I wasn't able to reliably parse Haskell code (especially given how well-suited Haskell is for parsing!).
同像性的真正意义在于宏语言、数据语言、AST 语言与程序输出统一为同一门语言。
同像性的要点在于:你的宏语言就是你的语言,你的数据结构语言就是你的语言,你的 AST 语言也是。它们全都是同一种语言。作者观察到“中间 AST”和“AST”共享同一具体语法、宏在两者之间变换是对的,但宏本身也是用这门语言定义的,程序的输出同样属于这门语言。
choeger查看英文原文
The point of homoiconocity is that your macro language is your language. And your data structure language is your language. As well as your AST language. They are all the same. So the author is right about observing that "intermediate ast" and "ast" share the same concrete syntax and macros transform one into the other. But macros are also defined in that language. Furthermore the output of your program is definitely in that language.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选