From murdoch at stats.uwo.ca  Tue May 26 21:18:19 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 26 May 2009 15:18:19 -0400
Subject: [Rd] Can a function know what other function called it?
In-Reply-To: <4A1C1F6D.8090103@dbmail.com>
References: <c2350ba40905231337u5ead6f97o95ee24f2faea081e@mail.gmail.com>	<4A1862AD.2070600@fhcrc.org>
	<4A19366F.5080402@stats.uwo.ca> <4A195872.5030507@dbmail.com>
	<4A1C0FC5.9010602@stats.uwo.ca> <4A1C1F6D.8090103@dbmail.com>
Message-ID: <4A1C407B.1090103@stats.uwo.ca>

On 5/26/2009 12:57 PM, Romain Francois wrote:
> Duncan Murdoch wrote:
>> On 5/24/2009 10:23 AM, Romain Francois wrote:
>>> Duncan Murdoch wrote:
>>>> On 23/05/2009 4:55 PM, Robert Gentleman wrote:
>>>>> Kynn Jones wrote:
>>>>>
>>> [snip]
>>>>>
>>>>>   and you have a breakpoint in bar, you could not (easily) 
>>>>> distinguish which of
>>>>> the two calls to bar was active. There is no line counter or 
>>>>> anything of that
>>>>> sort available.
>>>>
>>>> The evaluator doesn't pay any attention to srcref records, so this 
>>>> is still true, but it would be possible to keep the srcref on the 
>>>> stack as well as all the other info there.
>>>
>>> Please
>>
>> Here's a patch file that does this.  (Will it make it through to the 
>> mailing list?  We'll see.)  It's still in progress, so I'm not even 
>> ready to put it into R-devel, but you're welcome to try it out.
>>
>> The basic idea is that it attaches srcref attributes to the values 
>> returned from sys.calls (which won't be displayed, but if you want to 
>> play with them you can) and to .Traceback (which traceback() will 
>> display).  debug() will also show them.
>>
>> Not sure what bad side effects (e.g. on execution time) this has.
>>
>> Duncan Murdoch
> 
> Many thanks. I'll play with this right now. My guess is that since these 
> "srcref" records are calculated anyway by the parser, this won't affect 
> too much the execution time.

It does add a little extra execution time to every statement, and more 
to lines that have source references.  Whether enough to matter, I don't 
know.

Duncan Murdoch


> 
>>
>>>
>>>>
>>>> I've written code (and I think I sent it to you last year) that can 
>>>> do things like replacing the statement coming from a particular line 
>>>> of a file with whatever code you like; this could be used in writing 
>>>> a nice source-level debugger.
>>>
>>> yes
>>>
>>>>
>>>> Duncan Murdoch
>>>>
>>>>>
>>>>>  best wishes
>>>>>    Robert
>>>>>
>>>>
>>>
>>>
>>
> 
>



[Rd] Can a function know what other function called it?
Duncan Murdoch