[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(call/cc call/cc)




You know, you guys ARE dangerous.

I had seen (call/cc call/cc) mentioned in a previous post, but it 
quickly fell out of my 5 brain registers (I know, I'm on the weakish 
side). Tonight I remembered it on the tramway home, I tried to work 
it out without having anything to write on, and my head nearly 
exploded. You guys really are dangerous.

Anyway, it seems to work out as (cc cc) where cc is the current 
continuation. Is it right? For instance, in

(set! f (call/cc call/cc))

the continuation is

(lambda (x) (set! f x))

so that the above expands to

(set! f (lambda (x) (set! f x)))

executing it results in f being equal to (lambda (x) (set! f x)), and 
executing (f "Hello") results in f being set to "Hello". It seems to 
actually work this way when I try it. Please do reassure me about my 
sanity.

Also, if executed on a line of its own, the continuation of
(call/cc call/cc)
should be the identity function, which applied to itself gives again 
the identity function. But it is possible to capture it? It seems to 
me that any attempt to do so would cause the continuation to change, 
and therefore the above to evaluate to something different. Is the 
result of the above call ever escaping from the hand of the poor 
programmer?

Thanks for listening to all the ramblings,
						Luigi

--