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

From: Majorinc, Kazimir (kazimir at chem.pmf.hr)
Date: Fri Jul 27 22:09:25 EDT 2007

Chongkai Zhu wrote:
>>
>
> 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.
>
> Chongkai
>
Let us imagine I have large tree data structure of nodes and I want to 
calculate the SIZE of the subtree for some node. I can do it easily with 
some recursive function.

Now, my data structure is not the tree but it is more general graph. 
Using the same recursive procedure, there is a lot of redundancy. I can 
avoid that redundancy if I implement some kind of memoization of the 
SIZE and store values in some hash-table, or much better in the special 
field in the nodes of the graph. In both cases, I need to know whether 
procedure is called by itself (and then obey existing memoization) or it 
is called by some other function (and then initiate new memoization.)

There are few ways it can be done, for example, to define two 
procedures, SIZE and SIZE-PRIVATE (called only from SIZE), but it is 
certainly less elegant approach.






Posted on the users mailing list.