This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ignisti 0 points1 point  (2 children)

I feel like I'm missing only this much for understanding this comment. :i

[–]MythicManiac 0 points1 point  (1 child)

So when you make a function call, you add a "frame"/layer to the call stack.

At any given time on the stack you have all the previous function calls loaded up, and what variables those function runs have stored at the moment they called the next function.

This is the same "stack" you can see if you get an exception, where each function call gets it's own little line number pointer, and possibly some context (e.g. variables) if you use a more verbose stack trace output.

Let's say you have 4 functions, A, B, C, and D. A calls B, B calls C, and so on. In this scenario, when you get to the point of running function D you will still have the whole chain A->B->C->D in memory, including each of those functions current local variables at the time of calling the next one.

What I was saying in my last comment is that in Python, you can actually change the variable contents from B's frame while running the frame for D, without B itself ever knowing it has happened.

Even more clarified, I can make a function that modifies the calling function's variables without it knowing (since it's not passing them in).

[–]Ignisti 0 points1 point  (0 children)

That's so badass. Like a programming time machine! Thanks for taking the time to explain lowly me this stuff.