Is there a way of inspecting a continuation?

I'm pretty sure the answer is no, but I got to ask.

Is there a way of inspecting a continuation's "internals"?

By internals I mean things like its binding environment, the code that it is going to execute (file and line number perhaps), etc.

1 Like

In Racket CS, you can use the Chez Scheme inspector API. Use inspect at a terminal or inspect/object for programmatic inspection. Note that a Racket continuation has a k field with the Chez Scheme continuation (up to the nearest prompt).

laptop$ racket
Welcome to Racket v8.3.0.8 [cs].
> (require ffi/unsafe/vm)
> ((vm-eval 'inspect) (let/cc k k))
#[...]                                                            : ?

   fields .............. inspect fields
   name ................ inspect record name
   rtd ................. inspect record-type descriptor
   ref(r) .............. inspect named or nth element
   set! ................ set named element, if assignable
   show(s) ............. show contents of record
   ?? .................. display more options

#[...]                                                            : fields
(mc k winders mark-stack mark-splice tag)                         : up
#[...]                                                            : ref 1
#<continuation>                                                   : ?

   length(l) ........... display number of frame and closure variables
   depth ............... display number of frames in continuation stack
   ref(r) .............. inspect [named or nth] variable
   set!(!) ............. set [named or nth] variable to value, if assignable
   forward(f) .......... move to [nth] next frame
   back(b) ............. move to [nth] previous frame
   down(d) ............. inspect [nth] next frame
   closure(cp) ......... inspect the frame's closure, if any
   eval(e) ............. evaluate expression in context of current frame
   show(s) ............. show frame with free variables
   show-local(sl) ...... show frame without free variables
   show-frames(sf) ..... show the next [n] frames
   call ................ inspect the code for the pending call
   code(c) ............. inspect the code for the pending procedure
   file ................ switch to source file containing the pending call
   ?? .................. display more options

7 Likes