当前位置: 代码迷 >> 综合 >> sicp 习题2.5
  详细解决方案

sicp 习题2.5

热度:29   发布时间:2024-01-11 16:34:34.0
#lang planet neil/sicp
(define (cons a b) (* (expt 2 a) (expt 3 b)))
(define (car z)(if (= 0 (remainder z 2))(+ 1 (car (/ z 2)))0))
(define (cdr z)(if (= 0 (remainder z 3))(+ 1 (cdr (/ z 3)))0))运行:
> (define z (cons 2 3))
> (car z)
2
> (cdr z)
3
>