Join me for episode 201 of "gambit detective stories", today, we're going to try to solve the case of "how the f*ck does trace insert hooks" So looking at lib/_repl.scm , we see in ##trace that we have: (##interp-procedure-entry-hook-set! proc new-hook) which looks something like: (define-prim (##interp-procedure-entry-hook-set! proc hook) (let (($code (##interp-procedure-code proc))) (macro-code-set! $code (##fixnum.- (macro-code-length $code) 2) hook))) this "2" here looks like a magic constant, let's ignore it for now; looking for macro-code-set! in lib/_eval#.scm , we see: (##define-macro (macro-code-set! c n x) `(##vector-set! ,c (##fixnum.+ ,n 5) ,x)) now, this 5 here is anothe rmagical constant -- but this looks interesting; for the interpreter, does gambit basically store the procedure in a vector ... and for inserting traces, we just _DYNAMICALLY REWRITE THE CODE_ to insert stuff before & after? If so, this is really really cool. Any insights / clarifications / tips / deatils appreciated. Thanks!