【0x00】ANSI Common Lisp 学习笔记(1)
What is Lisp
Lisp语言是一种函数式程序设计语言。有别于命令式系内过程式的C、Fortran和面向对象的Java、C#等结构化程序设计语言。关于这些语言的区别,我们将会在以后的学习中慢慢体会。
约翰麦卡锡 (John McCarthy 1927-2011 R.I.P.) 和他的学生于 1958 年展开 Lisp 的初次实现 工作。 Lisp 是继 FORTRAN 之后,仍在使用的最古老的程序语言。更值得注意的是, 它仍走在程序语言技术的最前面。懂 Lisp 的程序员会告诉你,有某种东西使 Lisp 与众不 同。
Lisp与众不同的部分原因是它被设计成能够自己进化。你能用 Lisp定义新的Lisp操作符。当新的抽象概念风行时(如面向对象程序设计),我们总是发现这些新概念在Lisp是最容易来实现的。Lisp就像生物的DNA一样,这样的语言永远不会过时。
1.1 新的工具 (New Tools)
为什么要学 Lisp?因为它让你能做一些其它语言做不到的事情。如果你只想写一个函数来 返回小于 n 的数字总和,那么用 Lisp 和 C 是差不多的:
; Lisp (defun sum (n) (let ((s 0)) (dotimes (i n s) (incf si))))
1 /* C */ 2 int sum(int n){ 3 int i, s = 0; 4 for(I = 0; i < n; i++) 5 s+=I; 6 return(s) 7 }
如果你只想做这种简单的事情,那用什么语言都不重要。假设你想写一个函数,输入一个 数 n ,返回把 n 与传入参数 (argument)相加的函数。
1 ; Lisp (defun addn (n) 2 #'(lambda (x) 3 (+ x n)))
在C语言中 addn 怎么实现?你根本写不出来。
You might be woundering, why does someone will like to do things like this?
Well, people always learn to code with a certain programming language, Python and Pycharm for example, which will teach them only to do things the lauguage can do.So those who are learn Python as their first Programming language will never want to operate a sigle memory cell in RAM or to run the program without Pycharm, which are basic skills for those who use C to write a program.
In addition, there is another great feather of Lisp, which can be even more vailable than the feathre before. That feature is that Lisp programs are expressed as Lisp data structures so that you can write a program which can wirte a program on it own. Which is awesome.
By learning Lisp, one can learn to think in a new way when faceing a new problom and solve those problems in a sharp way.
Nov 25 2016
Half lost on my firmness gains to more glad heart,
Or violent and from forage drives
A glimmering of all sun new begun
Both harp thy discourse they march'd,
Forth my early, is not without delay;
For their soft with whirlwind; and balm.
Undoubtedly he scornful turn'd round ninefold,
Though doubled now what redounds,
And chains these a lower world devote, yet inflicted?
Till body or rare, and best things else enjoy'd in heav'n
To stand divided light at ev'n and poise their eyes,
Or nourish, lik'ning spiritual, I have thou appear.
—Henley
鸣谢:
Paul Graham,ANSI Common Lisp的作者

浙公网安备 33010602011771号