問題 2.5
;やべー、これは問題の日本語が意味わからない。 ;とりあえず、自分の問題解釈でとく (define (pow x y) (define (pow-iter x y p) (if (<= y 0) p (pow-iter x (- y 1) (* p x)))) (pow-iter x y 1)) (define (cons a b) (* (pow 2 a) (pow 3 b))) (define (cons-iter a p s) (if (= (remainder p s) 0) (cons-iter (+ a 1) (/ p s) s) a)) (define (car c) (cons-iter 0 c 2)) (define (cdr c) (cons-iter 0 c 3)) ;(car (cons 2 3)) ;-> 2 ;(cdr (cons 2 3)) ;-> 3 ;(car (cons 794 123)) ;-> 794 ;(cdr (cons 794 123)) ;-> 123 ;(car (cons 3245 3244)) ;-> 3245 ;(cdr (cons 3245 3244)) ;-> 3244 ;これでいいのかな?