awelgorithms

Read the current frame

Updated

The current frame is the top. That is the running call. Locals you can touch are that frame's. Buried frames' locals are frozen until they become top again.

What to focus on

Peek the explicit stack to see n, node, or phase. Do not scan down and mutate a buried frame. That is not how calls work.

Worked examples

top frame

a = [f(4), f(1)]
  1. current n=1

Result: f(1) running

after pop

a = [f(4)]
  1. current n=4

Result: f(4) running

empty

a = []
  1. no current frame

Result: not in a call

Try it

Write currentFrame(stack). stack is the non-empty call stack. Return the top frame. Do not write into a buried frame. a = [f(4), f(1)] → f(1) running. a = [f(4)] → f(4) running. a = [] → not in a call.

Empty is in the cases. There is then no current frame. The current frame is the top.