内容简介:使用 Lisp 简单描述加法运算
最近在看 MIT 公开课-计算机程序的构造和解释,即使你像我一样根本没学过 lisp 也能看懂下面这段代码,这段代码展示了怎么实现加法运算,这种我们几乎从来不会去想为什么的问题,这几行简单的代码告诉我们如何计算出 3 + 4 的值
由 皮亚诺 算术定义的求 x 和 y 之和的过程
; Define a [+] processor (define (+ x y) (if (= x 0) y (+ (-1+x) (1+y)))) ; x = 3, y = 4 (+ 3 4) (if (= 3 0) 4 (+ (-1+3) (1+4))) (+ (-1+3) (1+4)) (+ 2 5) (if (= 2 0) 5 (+ (-1+2) (1+5))) (+ (-1+2) (1+5)) (+ 1 6) (if (= 1 0) 6 (+ (-1+1) (1+6))) (+ (-1+1) (1+6)) (+ 0 7) (if (= 0 0) 7 (-1+0) (1+7)) 7
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- JavaScript中的加法运算
- 使用 Lisp 简单描述加法运算
- JS 加法知多少?
- 989-数组形式的整数加法
- 蓝桥杯 ADV-121 算法提高 高精度加法
- LeetCode每日一题: 数组形式的整数加法(No.989)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithm Analysis in Java
Mark A. Weiss / Pearson / 2011-11-18 / GBP 129.99
Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course wa......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!