On 03/30/2015 04:54 PM, Andrew Barnert wrote:
That skips over all the problems with your first version and immediately gets you your second version, and it avoids most of the problems there as well. The only thing you're missing in the end is the ability to convert functions to blocks and vice-versa at runtime. That's the part that causes all the problems, and I don't think is actually necessary for what you want (but if I'm wrong, I guess never mind:).
I don't think its necessary either and converting function blocks to an insertable code block isn't what I had in mind. If you can run a function block in specified frame, then it isn't needed. Just grab the current frame, execute the function block with it, as a function.
Of course the programmer would be responsible for making sure the names in the code block are available in the name space used with it. Name errors should propagate normally.
result = call_with_frame(function_code_object, sys.getframe(0))
But I think it will still runs into the name issues you mentioned earlier.
And as you also mentioned it's quite possible someone has already done a call_with_frame function. I just haven't found it yet.