Skip to content

Instantly share code, notes, and snippets.

@vyzo
Last active February 5, 2018 19:21
Show Gist options
  • Save vyzo/ec2e6eb64e806085efeef7a645dda3df to your computer and use it in GitHub Desktop.
Save vyzo/ec2e6eb64e806085efeef7a645dda3df to your computer and use it in GitHub Desktop.
log/caller
(def (get-caller cont)
(let lp ((cont cont))
(and cont
(or (##continuation-creator cont)
(lp (##continuation-next-frame cont #f))))))
(def (log/caller fmt . args)
(continuation-capture
(lambda (cont)
(let (caller (get-caller cont))
(when caller
(display (or (##procedure-friendly-name caller) '?))
(display ": "))
(apply printf fmt args)))))
(def (foo)
(log/caller "hello world~n")
(void)) ; inhibit tail context
> (foo)
foo: hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment