编程语言与软件工程2017people.csail.mit.edu
D-Expressions:Lisp 的力量,Dylan 风格
D-Expressions: Lisp power, Dylan style
进阶 · 约 60 分钟读完前置知识:Lisp 宏、Dylan 语言基础、程序语言设计
导读
这篇论文提出 D-Expressions,试图在 Dylan 这类 Algol 风格语法的语言中实现 Lisp 式的宏能力,让语法可由程序员扩展。它探讨了如何兼顾传统中缀语法与 Lisp 宏的表达力。
HN 关注点:HN 读者长期关注 Lisp 宏与语法设计之争,这篇论文触及“能否在非 S 表达式语法中拥有 Lisp 能力”这一经典话题。
HN 评论精选
这几条评论里:支持 2 补充 1 亲历 1
支持为 Lisp 语法辩护:规则极简,学习成本在于函数和宏而非语法本身
我知道乍看之下会困惑,但 Lisp 语法其实是最好的。一分钟就能教会别人:(<函数或宏名> 参数1 参数2 ...),这就是全部语法。函数调用时参数从左到右求值再调用,占 95% 的情况;宏则要读文档,因为每个宏都是 DSL,占 5%。学 Lisp 的复杂度全在于了解函数和各宏的 DSL。Clojure 加了 [] {} 等字面量语法,有利有弊。给语法两三个月、每周 40 小时的适应时间,你肯定会喜欢它。
didibus查看英文原文
I know at first it looks confusing, but the lisp syntax is pretty much the best. I can teach it to someone in 1 minute: (<function or macro name> arg1 arg2 ...) That's it. This is 100% of the syntax. If dealing with a function, the evaluation will always be arguments from left to right are evaluated first, and then the function is called with the result of evaluating the args. This is 95% of the cases. If dealing with a macro, go read the documentation for it, because every macro is a DSL, and evaluation can happen in different ways. This is the 5% case. All the complexity of learning a lisp comes from knowing more functions, what they do and how to use them, and learning each macro's DSL. Can this syntax be improved on, I'm not so sure. Clojure added some special syntax for some more literals, such as [] for vectors, {} for map, etc. And I do think in one way they help, but in others they hurt. Maybe adding something that distinguishes a macro from a function, but once you know the names of them, the name is enough to know. Maybe make it so there is a more visible demarcation between the function/macro name and the arguments. Not sure how though. All that to say, if you give the ayntax a good chance, like 2 to 3 months of 40h a week for your brain to more clearly see where the functions start and end, I'm sure you'll like it.
补充补充相关资料:Honu 语言也做了类似方向,允许宏定义中缀操作符
另一种有类似宏系统的 Algol 风格语言是 Honu(https://www.cs.utah.edu/~rafkind/papers/dissertation.pdf)。它更进一步,允许宏定义新的中缀操作符,其分层方法(在解析中交错进行 enforest 步骤)值得一看。
panic查看英文原文
Another Algol-style language with a macro system in this vein is Honu (https://www.cs.utah.edu/~rafkind/papers/dissertation.pdf). It goes slightly further, allowing macros to do things like define new infix operators, and its layered approach (with an "enforest" step interleaved with parsing) is worth a look.
亲历作者相关者现身:第一作者的学生发布了继承其思想的新语言 Stanza
大家好。论文第一作者 Jonathan Bachrach 是我的博士导师,几个月前我们基于类似思想发布了一门新语言 Stanza。Stanza 可算是 Dylan 的精神继承者:有可选类型系统、协程、基于多方法的对象系统、可编程宏和基于 s 表达式的自然语法,见 www.lbstanza.org。—— Patrick
patricksli查看英文原文
Hello everyone. Since there's been interest in the D-expressions paper, I wanted to add that Jonathan Bachrach (the first author on the paper) is actually my Ph.D. advisor, and we just released a new programming language a few months ago called Stanza based on similar ideas. Stanza is a spiritual successor to Dylan of sorts: it has an optional type system, coroutines, a multimethod-based object system, programmatic macros, and an s-expression-based natural syntax. You can check it out at www.lbstanza.org. - Patrick
支持肯定 Dylan 的语言设计:可选类型、纯 OO、多重分派是优秀特性组合
Dylan 做对了很多事——语法虽然太啰嗦——但可选静态类型、纯面向对象、多重分派……这套特性组合会让我非常有生产力。
lacampbell查看英文原文
Dylan did so much right. Well - the syntax was too verbose - but optional static types, pure OO, multiple dispatch.. that's an amazing set of features that would make me very productive.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2017Hacker News 讨论帖82 分 · 89 评
- 2024Hacker News 讨论帖89 分 · 61 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选