
Scheme
文章平均质量分 71
yaojiank
这个作者很懒,什么都没留下…
展开
-
SICP习题解答1.1-1.8
ex1.1-1.5#lang racket; exercise 1.110(+ 5 3 4)(- 9 1)(/ 6 2)(+ (* 2 4) (- 4 6))(define a 3)(define b (+ a 1))(+ a b (* a b))(= a b)(if (and (> b a) (< b (* a b))) b a)(con原创 2012-08-16 15:57:12 · 572 阅读 · 0 评论 -
SICP习题解答1.9-1.19
ex1.9-1.10#lang racket; exercise 1.9;; 第一个是递归计算过程,第二个是迭代计算过程; exercise 1.10(define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A (- x 1) (A x (-原创 2012-08-17 19:32:16 · 2149 阅读 · 0 评论 -
SICP习题解答1.20-1.28
ex1.20-1.22#lang racket; exercise 1.20;; 正则序求值(gcd 206 40) 18次(判断14次 求值4次);; 应用序4次; exercise 1.21(define (smallest-divisor n) (find-divisor n 2))(define (find-divisor n test-divisor) (co原创 2012-08-18 10:59:18 · 1101 阅读 · 0 评论 -
SICP习题解答1.29-1.39
ex1.29#lang racket; exercise 1.29(define (integ f a b n) (define h (/ (- b a) n)) (define (term k) (define y (f (+ a (* k h)))) (cond ((or (= k 0) (= k n)) y) ((even? k) (*原创 2012-08-19 13:53:22 · 826 阅读 · 0 评论 -
SICP习题解答1.40-1.46
ex1.40#lang racket; exercise 1.40(define (newtons-method g guess) (fixed-point (newton-transform g) guess))(define (newton-transform g) (lambda (x) (- x (/ (g x) ((deriv g) x)))))(define (d原创 2012-08-19 20:44:10 · 672 阅读 · 0 评论 -
SICP第一章小结
Lisp作为函数式语言,目前来看语法简单,使用起来相当方便。起初看Lisp是因为Hadoop编程借口是函数式的(Map/Reduce方法),所以想学习一下函数式语言。现在花了4天时间把终于第一章看完了,简单的小结一下。第一章讲的是Lisp的过程,里面有几个比较重要的特性:Lisp的代换模型:正则序(先代入再求值)、应用序(先求值再代入)。Scheme默认是应用序,这样可以简化计算。原创 2012-08-20 10:15:40 · 486 阅读 · 0 评论 -
SICP习题解答2.7-2.16
ex2.7-2.16#lang racket; exercise 2.7(define (make-interval a b) (cons a b))(define (upper-bound interval) (max (car interval) (cdr interval)))(define (lower-bound interval) (min (car interval原创 2012-08-31 10:46:19 · 775 阅读 · 0 评论 -
SICP习题解答2.1-2.6
ex2.1-2.4#lang racket; exercise 2.1(define (make-rat n d) (define g (gcd n d)) (let ((g1 (if (< d 0) (- g) g))) (cons (/ n g1) (/ d g1))))(define (gcd a b) ;; 返回正最大公约数 (if (= b 0)原创 2012-08-21 22:20:25 · 1293 阅读 · 0 评论 -
SICP习题解答2.17-2.23
#lang racket; exercise 2.17(define (last-pair l) (cond ((null? l) null) ((null? (cdr l)) l) (else (last-pair (cdr l)))))(last-pair (list 23 72 149 34))(last-pair '(1))(last-pai原创 2012-09-01 12:59:41 · 1186 阅读 · 0 评论