Function rooms in 3D
About this app
Enter Python code or pick an example — every function call builds its own room: a code board shows the running line and plugs in values, crates hold the local variables, value orbs fly along cables and back. Recursion grows a tree of rooms; scrub the timeline or step through.
What happens in a function call
When a Python program calls a function, a new call frame with its own local variables is created. The arguments are bound to the parameters, the caller waits until return hands back a value, and then the frame disappears together with its variables. In recursion a function calls itself: g(7) and g(6) are then two different frames, each with its own n. All calls currently waiting form the call stack, and the top one is working.
What the app shows
Every call becomes a room in 3D. A code board on the back wall shows the running line; conditions get a tick or a cross, and a substitution line replaces names with values, so “7 + g(6)” becomes “7 + 21”. Crates on the floor hold the local variables. Arguments fly in as orbs along a cable through the door, and results fly back to the caller. In recursion the rooms grow on terraces into a tree, and finished rooms dissolve.
Try it yourself
Pick an example (g and f, factorial, Fibonacci) or type your own code; def, assignments, if/elif/else, return and arithmetic expressions are supported. Then scrub along a timeline, go step by step or let it play. A stack view lists all existing calls, and the camera follows the active room or shows the whole tree.
Frequently asked questions
- What is a call stack?
- The call stack holds every function call that has started but not yet finished. Each entry (frame) contains the local variables and the place where execution continues after the return. The top frame is working; all frames below it are waiting for its result.
- How does recursion work?
- A recursive function calls itself with a smaller problem until it reaches a base case that makes no further call. Then the results travel back through the waiting calls. For the factorial, fact(3) waits for fact(2), which waits for fact(1).
- What are local variables in Python?
- Variables assigned inside a function, including its parameters. They exist only in the frame of that particular call and disappear when the function returns. Two calls of the same function therefore have separate local variables.
- Can I enter my own code in Function rooms?
- Yes, in the code panel. A deliberately small part of Python is supported: def, assignments, if/elif/else, return, arithmetic, comparisons and and, or and not. Loops, lists and classes are not included.
Subject: Computer science
More from Computer science
- Ackermann function
- Elevator simulator
- Binary workshop
- Binary versus linear search
- The Collatz problem
- Inside a CPU
- Swap the inside
- One frame in 16 milliseconds — how a game engine renders an image (3D)
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps