Hatena::Grouphokudaisicp

TSBの日記

2008-12-08

2.2.2

| 17:54


;;2.2.2

(define (count-leaves x)
  (cond ((null? x) 0)
	 ((not (pair? x)) 1)
	 (else (+ (count-leaves (car x))
	 	   (count-leaves (cdr x))))))

(define x (cons (list 1 2) (list 3 4)))
(print (length x))
(print x)

(define x2 (cons (list 1 2) (list (list 3 4) 5)))
(print (length x2))
(print x2)

(define x3 (cons (list 10 11) x))
(print (length x3))
(print x3)

(define x4 (cons x (list 11 12)))
(print (length x4))
(print x4)
(print (cdr x4))

(define x5 (cons x x))
(print (length x5))
(print x5)

(define x6 (cons x (list x x)))
(print (length x6))
(print x6)
(print (count-leaves x6))

;;2.24
(define tree1 (cons 1 (list 2 (list 3 4))))
(print tree1)
(print (length tree1))
(print (count-leaves tree1))

;;2.25
(define 7tree1 (list 1 3 (list 5 7) 9))
(print 7tree1)
(print (cdr (car (cdr (cdr 7tree1)))))

2008-12-01

1.3 --- 1-44 途中

| 17:56

(define (3heikin a b c) (/ (+ a b c) 3))

(define (inc x) (+ x 1))

(define (square x) (* x x))

(define (compose proc2 proc1) (lambda(x) (proc2 (proc1 x)) ) )

(define (repeated proc num) (

if(> num 0) (lambda(x) ( (repeated proc (- num 1)) (proc x) ) )

(lambda(x) x) ))

(define dx 0.000001)

(define (smooth f) (lambda(x) (3heikin (f (+ x dx)) (f x) (f (- x dx)) ) ))

(print ( (smooth square) 10))

(print ( (repeated (smooth square) 5) 10))

1.3 --- 1-43

| 17:24

(define (inc x) (+ x 1))

(define (square x) (* x x))

(define (compose proc2 proc1) (lambda(x) (proc2 (proc1 x)) ) )

(define (repeated proc num)

(

if(> num 0) (lambda(x) ( (repeated proc (- num 1)) (proc x) ) )

(lambda(x) x)

)

)

(print ( (repeated square 3) 5))

以上のやつはだめみたい。

procが重なってない。

単純に計算を逐次的にやってるように見えるだけ?

1.3 --- 1-42

| 16:34

(define (inc x) (+ x 1))

(define (square x) (* x x))

(define (compose proc2 proc1) (lambda(x) (proc2 (proc1 x)) ) )

(print ( (compose square inc) 6) )

1.3 --- 1-41

| 16:29

(define (inc x) (+ x 1) )

(define (double f) (lambda(x) (f (f x) )))

(print (((double (double double)) inc) 5) )