经过一些工作后,我能够理解该multirember&co
功能,但我无法从以下multiinsertLR&co
代码中真正理解(第 143 页):
(define multiinsertLR&co
(lambda (new oldL oldR lat col)
(cond
((null? lat)
(col '() 0 0))
((eq? (car lat) oldL)
(multiinsertLR&co
new
oldL
oldR
(cdr lat)
(lambda (newlat L R)
(col (cons new
(cons oldL newlat))
(add1 L) R))))
((eq? (car lat) oldR)
(multiinsertLR&co
new
oldL
oldR
(cdr lat)
(lambda (newlat L R)
(col (cons oldR
(cons new newlat))
L (add1 R)))))
(else
(multiinsertLR&co
new
oldL
oldR
(cdr lat)
(lambda (newlat L R)
(col (cons (car lat)
newlat) L R)))))))
这本书似乎没有解释collector
在评估函数时最初应该通过哪一个,所以我分别使用了第 138 页和第 140 页上解释的a-friend
收集器和收集器。last-friend
使用任一收集器评估函数会导致以下错误(使用带有 petit chez 方案的跟踪函数):
>> (multiinsertLR&co 'salty 'fish 'chips '(chips and fish or fish and chips) last-friend)
|(multiinsertLR&co salty fish chips (chips and fish or fish and chips)
#<procedure>)
|(multiinsertLR&co salty fish chips (and fish or fish and chips)
#<procedure>)
|(multiinsertLR&co salty fish chips (fish or fish and chips) #<procedure>)
|(multiinsertLR&co salty fish chips (or fish and chips) #<procedure>)
|(multiinsertLR&co salty fish chips (fish and chips) #<procedure>)
|(multiinsertLR&co salty fish chips (and chips) #<procedure>)
|(multiinsertLR&co salty fish chips (chips) #<procedure>)
|(multiinsertLR&co salty fish chips () #<procedure>)
Exception: incorrect number of arguments to #<procedure>
Type (debug) to enter the debugger.
我查看了几次代码,但找不到错误。如果有人有任何见解,请分享。如果有人也可以通过一些好的例子向我指出(相对而言)对延续的温和解释,那也将不胜感激。