码迷,mamicode.com
首页 > 其他好文 > 详细

SICP_3.24

时间:2017-05-06 01:08:15      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:roc   cal   else   local   record   tab   als   oca   records   

 1 (define (make-table key-same?)
 2   (let ((local-table (list *table*)))
 3 
 4     
 5     (define (assoc key records)
 6       (cond ((null? records) #f)
 7             ((key-same? (caar records) key) (car records))
 8             (else (assoc key (cdr records)))))
 9 
10     (define (lookup key-1 key-2)
11       (let ((subtable (assoc key-1 (cdr local-table))))
12         (if subtable
13             (let ((record (assoc key-2 (cdr subtable))))
14               (if record
15                   (cdr record)
16                   false))
17             false)))
18 
19     (define (insert! key-1 key-2 value)
20       (let ((subtable (assoc key-1 (cdr local-table))))
21         (if subtable
22             (let ((record (assoc key-2 (cdr subtable))))
23               (if record
24                   (set-cdr! record value)
25                   (set-cdr! subtable (cons (cons key-2 value)
26                                            (cdr subtable)))))
27             (set-cdr! local-table
28                       (cons (list key-1 (cons key-2 value))
29                             (cdr local-table)))))
30       ok)
31 
32     (define (dispatch m)
33       (cond ((eq? m lookup-proc) lookup)
34             ((eq? m insert-proc!) insert!)
35             (else (error "Unknow operation --TABLE" m))))
36 
37     dispatch))

这一题没什么难道。

SICP_3.24

标签:roc   cal   else   local   record   tab   als   oca   records   

原文地址:http://www.cnblogs.com/tclan126/p/6815445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!