编程与软件工程funcall.blogspot.com
又不是 Lisp(2009)
Not Lisp again (2009)
2009 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一篇 2009 年的博客文章,作者借一个用 Lisp 求导的课堂式示例,展示 Lisp 如何用很少的代码表达计算与数学概念。文中演示与 SICP 的结构相近,因此多年来常被用来讨论 Lisp 的一等函数、闭包和函数式思维。
为什么经久不衰:它把 Lisp 的抽象威力压缩进一个短小经典例子中,并且每次重读都能把读者引回 SICP 与函数式编程的根本洞见。
HN 评论精选
推荐 SICP,并指出文中演示与 SICP、Abelson 的直接渊源。
如果这个对 Lisp 和计算模型的介绍正好对上了你的思路,那你应该去读《计算机程序的构造和解释》(SICP)。原文演讲中的 Abelson 正是该书的合著者,而这里描述的演示完全遵循该书的结构(包括导数例子)。多年前我第一次读它(并做完习题)时,它为我打开了一种思考编程的新方式。
dharmon查看英文原文
If this presentation of Lisp and model of computation clicks with you, you owe it to yourself to read Structures and Interpretations of Computer Programs (SICP). The Abelson from the OP's lecture is the co-author, and the presentation described exactly follows the structure of the book (including the derivative example). It opened my eyes to a new way of thinking about coding when I first read it (and worked through the exercises) many years ago.
质疑文章夸大 Lisp 的独特性,指出 C 和 Python 也能优雅实现导数。
我之前那条有点暴躁的评论被踩下去了,但我确实认为这里把 Lisp 的“高阶魔法”和“能做微积分”夸大了。用 80 年代的 C 配合函数指针求 N 阶导数并不算糟糕;Python 的高阶函数写法也同样优雅(评论中给出了代码)。
QuadrupleA查看英文原文
My previous, somewhat-cranky comment got downvoted away, but I do think Lisp's "higher-order magic" and "ability to do calculus" is being a bit exaggerated here. From below - evaluating an Nth derivative in 80s-era C is not so atrocious: #define DX 0.0001 typedef double (*func)(double); double NthDeriv(int n, func f, double x) { if (n == 1) { return (f(x + DX) - f(x)) / DX; } else { return (NthDeriv(n - 1, f, x + DX) - NthDeriv(n - 1, f, x)) / DX; } } double Cube(double x) { return x * x * x; } double result = NthDeriv(3, &Cube, 5.0); As mentioned in previous discussions of this article, the equivalent in Python is pretty elegant: >>> def deriv(f): ... dx = 0.0001 ... def fp(x): ... return (f(x + dx) - f(x)) / dx ... return fp ... >>> cube = lambda x: x**3 >>> deriv(cube)(2.0) 12.000600010022566
强调闭包和一等函数可返回导数函数,并能用于自动构造物理向量场。
真正的力量不只是对给定函数求导;正如别人指出的,用 C 的函数指针也能做到。拥有一等过程和闭包意味着你能把导数本身作为函数返回,这让你做到简单例子没展示的事情。物理例子:给定描述机械系统的哈密顿量(广义能量),你可以自动构造计算相应哈密顿向量场的函数;把向量场和初始条件交给数值积分器,就能得到轨迹。
kkylin查看英文原文
The real power of this isn't just differentiating a given function; as others have pointed out, you can do this in, e.g., C with function pointers. Having first-class procedures and closures means you can actually return the derivative as a function. This lets you do things that the simple example doesn't show. For a physics example, see https://mitpress.mit.edu/sites/default/files/titles/content/sicm/book-Z-H-37.html#%_sec_Temp_235 : given a Hamiltonian (generalized energy) describing a mechanical system, you can automatically construct a function that computes the associated Hamiltonian vector field. Pass the vector field and an initial condition into a numerical integrator, and out pops the trajectory.
总结今天人们对 Lisp 的常见六类反对意见。
作者当年遇到的反对意见,已经不再是今天主流语言程序员反对 Lisp 的理由。如今我听到的反对意见更像是:1. 括号太多(仍是头号反对);2. Lisp 看起来、用起来不像我习惯的东西;3. Lisp 库不如最流行主流语言多;4. Lisp 程序员少,用 Lisp 时难招人;5. Lisp 工作少,学了也难找相关工作;6. Lisp 太古老,老东西在新语言面前显得无用原始。
pmoriarty查看英文原文
The objections the author had way back in the day are no longer the objections programmers of mainstream languages have to Lisp today. Today the objections I hear are more along the lines of: 1 - All those parenthesis. (Still a top objection) 2 - Lisp doesn't look like or work like what I'm used to. 3 - Lisp doesn't have as many libraries as the most popular mainstream programming languages. 4 - There aren't nearly as many Lisp programmers, so it'll be hard to find more to join your project/company if you use Lisp. 5 - There aren't nearly as many Lisp jobs, so why bother learning Lisp if you're going to have a hard time finding work using it? 6 - Lisp is ancient, and anything that old is useless and primitive compared to new and shiny languages.
历次讨论
同类还值得读
开源应用架构
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编辑精选