首页 > 代码库 > SICP_3.24
SICP_3.24
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。