[plt-scheme] Does the procedure know who called it and how many times?

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Fri Jul 27 21:29:17 EDT 2007

Majorinc, Kazimir wrote:
> I need "..." parts
> (define (f x)
>  (let ((p ... ))
>        (display "I'm called by ") (display p))
>        (if (eq? p f)
>            (let ((n ...))
>                 (display "I called myself recursively ")
>                 (display n)
>                 (display " times."))))
>        (do something)))
> Is there any way I can do it without defining new argument of f or new 
> global variable?
> Thank you.

Why do you need that? "Continuation Marks" is the closest thing I can 
think of. But if a function `foo' calls your `f' in tail position, the 
continuation mark of `foo' won't be available. Besides, the function 
calls you can install whatever mark they want.


Posted on the users mailing list.