编程与软件工程norvig.com编辑精选
如何用 Python 编写一个(Lisp)解释器
(How to Write a (Lisp) Interpreter (in Python))
2010 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Peter Norvig 写的一篇经典教程,用约一页 Python 代码实现一个 Lisp 解释器(名为 lispy):从分词、解析到求值,支持变量、函数定义、条件分支与递归,最终能跑阶乘等小程序。它把「解释器」这个看似神秘的部件拆成几十行可读代码,读完就能自己动手复现。
为什么经久不衰:它证明了一门语言的求值核心可以压缩到一页代码,几十年后仍是理解解释器、eval/apply 与 Lisp 本质的最短路径。
HN 评论精选
推荐同作者的进阶续篇 lispy2。
也一定要看看续篇《如何写一个(更好的)Lisp 解释器(用 Python)》:http://norvig.com/lispy2.html
kroger查看英文原文
Be sure to also check "(How to Write a ((Better) Lisp) Interpreter (in Python))": http://norvig.com/lispy2.html
感叹 Norvig 代码的简洁与表达力。
每次读 Norvig 的代码,编程都显得那么简单而强大,我就纳闷自己费了那么大劲,怎么只得到这么点成果。
jimbokun查看英文原文
Every time I read code from Norvig, programming seems so simple and powerful, and I wonder how it is I spend such effort getting such meager results.
推荐两本深入讲解 Lisp 实现的经典书籍。
想更深入钻研 Lisp 解释器的,可以读 Christian Queinnec 的《Lisp in Small Pieces》,这是该领域的经典参考书之一。大学时我们还有一本讲函数式语言实现的 Peter Kogge《The Architecture of Symbolic Computers》,也很好。
sb查看英文原文
For those interested in a more in-depth treatment of Lisp interpreters: "Lisp in Small Pieces", by Christian Queinnec is one of the canonical references in that area. (http://www.amazon.com/exec/obidos/ASIN/0521562473) At university we had a copy on implementation of functional programming languages following "The Architecture of Symbolic Computers" by Peter Kogge, which is very good, too. (http://www.amazon.com/exec/obidos/ASIN/0070355967)
用 Alan Kay 的话点出「一页代码实现 Lisp」的意义。
我喜欢那句话:强大的语言应该能塞进一页代码。Alan Kay 说过:我曾断言你能用「一页代码」定义「世界上最强大的语言」,最初这么吹是因为 McCarthy 那个自描述的 Lisp 解释器是用 Lisp 自己写的——大约「一页」,而论威力,Lisp 对函数式语言来说就是全部家当。
kroger查看英文原文
I like the quote that a powerful language should fit a page of code: "I asserted that you could define the "most powerful language in the world" in "a page of code." I had orignally made the boast because McCarthy's self-describing LISP interpreter was written in itself. It was about "a page", and as far as power goes, LISP was the whole nine-yards for functional languages." --- Alan Kay in http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html
历次讨论
同类还值得读
开源应用架构
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编辑精选