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

sicp 习题2.24 2.25

热度:85   发布时间:2024-01-11 16:32:42.0

它的盒子图形如下:
 (1 (2 (3 4)))       ((2 (3 4)))
[*]---------------> [*]|                   ||                   |v                   v (2 (3 4))         ((3 4))1                  [*]---------------> [*]|                   ||                   |v                   v (3 4)             (4)2                  [*]---------------> [*]---------------> '()|                   ||                   |v                   v3                   4
它的树图形如下:(1 (2 (3 4)))*/ \/   \  (2 (3 4))
1     */ \/   \  (3 4)2     */ \/   \3     4

习题2.5
(define x (list 1 3 (list 5 7) 9))
run:

Welcome to DrRacket, version 5.3.3 [3m].
Language: planet neil/sicp; memory limit: 512 MB.
> (car (cdr (car (cdr (cdr x))))) 
7

#lang planet neil/sicp
(define x (list (list 7)))
run:

> (car x)
(mcons 7 '())
> (caar x)
7

(define x (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7)))))))
run:

> (car (cdr (car (cdr (car (cdr (car  (cdr (car (cdr (car (cdr x))))))))))))
7