[plt-scheme] continuation comparison

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Fri Jul 18 14:24:20 EDT 2003

PLT peeps-

Does MzScheme provide a continuation comparison procedure that tells 
you if a continuation K1 is an extension of another argument 
continuation K2?  I'm using the term "extension" here in [i think] the 
same sense that it is used in the description of 
CALL-WITH-ESCAPE-CONTINUATION, so if   (continuation-extends? k1 k2) 
==> #t, then k2's activation frame sequence is a prefix of k1's 
activation frame sequence.

I believe such a relation could almost be implemented in user code if 
the user instrumented the code with continuation-marks (perhaps by 
redefining CALL/CC and its brethren to make the appropriate calls to 
WITH-CONTINUATION-MARK) *except* that the CURRENT-CONTINUATION-MARKS 
only works on the current continuation, which is not what we're working 
with above; what you really want instead is a mapping from an arbitrary 
continuation to its marks, CONTINUATION->CONTINUATION-MARKS.  I don't 
see such functionality in the reference manual; perhaps it could be 
added?

But in any case, it would be a little more convenient if one did not 
have to do the instrumentation and instead a primitive operation for 
comparing two continuations was provided.

I think I would like such a procedure, because it would allow me to 
write a variant of the AMB and NEXT logic programming operators where 
NEXT could take arguments that represented the variables that we want 
new values for.  This came up in a project of mine where the system was 
spending a lot of time trying to find a solution for some constraint 
F(U,V,W,X,Y,Z) where it knew on each iteration that only a particular 
pair of variables from the set {U,V,W,X,Y,Z} were incompatible (lets 
say it was X and Y), and so we didn't want to waste time trying out new 
values for Z when we knew that we needed to move on to new values for X 
or Y.

-Felix

p.s. while writing this email, I thought of other ways to handle this 
particular case; notably, if the whole set of logic variables is known 
at the time NEXT is called, then instead of passing X,Y as arguments, 
you could pass the set-difference {U,V,W,Z}.  Then the code for NEXT 
would inspect the variable defined at each AMB call, and if it were one 
of the variables in the difference above (lets say its Z), then it 
would go ahead and skip to the exit continuation instead of trying out 
a new value for Z.   And admittedly, I'm hard pressed to think of a 
case where this human-developed optimization is possible when the human 
DOESN'T already know the whole set of logic variables.



Posted on the users mailing list.