【发布时间】:2012-08-26 01:36:05
【问题描述】:
经过一些工作,我能够理解 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,所以我使用了a-friend 收集器和last-friend 收集器,分别在第138 页和第140 页解释。使用任一收集器评估函数会导致以下错误(使用带有 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.
我多次查看代码,但找不到错误。如果有人有任何见解,请分享。如果有人也可以通过一些好的例子向我指出(相对而言)对延续的温和解释,那也将不胜感激。
【问题讨论】:
标签: lambda scheme continuations the-little-schemer