I was able to grok the multirember&co
function after some work, but I can't really make much sense out of the following multiinsertLR&co
code (p. 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)))))))
The book doesn't seem to explain which collector
one should initially pass when evaluating the function, so I used the a-friend
collector and last-friend
collector explained on pages 138 and 140, respectively. Evaluating the function with either collector results in the following error (using the trace function with petit chez scheme):
>> (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.
I looked over the code several times, but couldn't find the error. If someone has any insight, please share it. If anyone could also point me to a (relatively speaking) gentle explanation of continuations with some good examples, that would be much appreciated as well.