Skip to content

Commit f5f768b

Browse files
committed
Replace mcons with build-in mlist function
1 parent 0362825 commit f5f768b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

chapter3/1d-table.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#lang racket
2+
(require compatibility/mlist)
23

34
(define (make-table)
4-
(mcons '*table* '()))
5+
(mlist '*table*))
56

67
(define (assoc key records)
78
(cond ((null? records) false)

chapter3/2d-table.rkt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#lang racket
22
(require "1d-table.rkt")
3+
(require compatibility/mlist)
34

45
(define (make-table)
56
(let ((local-table (mcons '*table* '())))
@@ -20,10 +21,9 @@
2021
(set-mcdr! record value)
2122
(set-mcdr! subtable (mcons (mcons key-2 value)
2223
(mcdr subtable)))))
23-
(set-mcdr! local-table (mcons
24-
(mcons key-1
25-
(mcons (mcons key-2 value) '()))
26-
(mcdr local-table)))))
24+
(set-mcdr! local-table (mcons (mlist key-1
25+
(mcons key-2 value))
26+
(mcdr local-table)))))
2727
'ok)
2828
(define (dispatch m)
2929
(cond ((eq? m 'lookup-proc) lookup)

chapter3/exercise3-25.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#lang racket
2+
(require compatibility/mlist)
23

34
;;; 实现与一维数组一致,差别在于 key 的表达方式,与原来使用 'a 的字符
45
;;; 变量作为 key 不同,现在使用 '(a b) 列表作为 key
56
(define (make-table)
6-
(let ((local-table (mcons '*table* '())))
7+
(let ((local-table (mlist '*table*)))
78
(define (assoc key records)
89
(cond ((null? records) false)
910
((equal? key (mcar (mcar records)))

0 commit comments

Comments
 (0)