REPL might be essential for AI problem-solving
Note: this is an unfinished post. I took time to refine.
Many programming problems cannot be solved with static code alone; they require interaction with the program’s dynamic state, yet current AI systems typically operate with limited access to that state.
Resume
AI code assistants focus on producing and editing code, typically using only static information: the code they are editing. While programming, humans typically imagine the program state at the point where they are editing⁽¹⁾. This is especially true when using a REPL style of programming (Read-Eval-Print-Loop).
We believe this change is essential for LLMs to find and resolve programming errors, as understanding the dynamic state is typically a core part of debugging.
I also believe this might be connected to central open questions about LLMs, such as why, if they are so smart, they can’t play simple games like tic-tac-toe (or variants of it).
(1) We can think of the state as the set of symbols and values associated with that symbol.
About REPL
Traditionally, programming consists of producing a program: a bunch of lines of code.
A program, when executed, produces a dynamic state, which we will call a process. To simplify it, we can think of the values of each symbol at a given point of execution.⁽²⁾ Notice that (under our definition) a process is represented by a data structure: a process is data.
The contrast with REPL is the mainstream ECR (Edit-Compile-Run) loop, where the state starts from scratch. ECR was entitled by its reproducibility, but trivially, one can reconstruct the executed program in a REPL environment, as we show in the practical example below.
(2) Notice it might be more complex than that, as other symbol references as the loaded modules, opened files, web sessions, etc., are part of the dynamic state of the program.
REPL applications
REPL accelerates feedback, making it a natural fit for learning, science, and exploratory programming. However, we believe it’s also essential for some problem-solving tasks, such as debugging (or any other problem that requires interactivity), as exemplified in the sections below.
REPL vs Traditional programming
Referring back to our definitions of programs vs processes:
- Traditional programming (ECR) focuses on outputting programs.
- REPL focuses on the output processes (data).
REPL shifts the programming target from programs → processes.
Note: With that distinction in mind, it’s not surprising that REPL is so popular in fields such as data science and scientific programming. But the question is: which other fields/problems are easier to address with this alternative paradigm? why? Do they have something in common?
Why REPL might be so powerful for AI?
- Right now, we don’t use the dynamic information. And there are things that can only be inferred at runtime (for instance, the fields of a Python dictionary, the distribution of a dataset, etc.)
- REPL speeds up the feedback loop in verifiable fields, which is very desirable for AI.⁽³⁾
- We believe that REPL is more aligned with problems that require interactivity. These are not rare problems limited to data science and scientific programming; we solve them daily as software engineers when we handle database migrations and backward/forward compatibility across a system of components. Other problems, such as web scraping, are clearly interactive problems: you refine the extracted data iteratively until you get what you want.
(3) Some ECR methodologies, such as TDD, also rely on tight feedback loops. TDD arguably offers advantages over REPL development with respect to reproducibility⁽⁴⁾. However, a REPL does not require rebuilding the full state on every iteration, which, for certain tasks, can be prohibitively expensive or even impossible.
(4) REPL can be equipped with operations such as save_state and rollback(), allowing the system to rewind to a previous state when necessary or preserve the information of a given state for later reproduction.
Problems that can be solved by REPL
WIP 🛠️
Special mention to FastAI / Jeremy Howard
A special mention to Jeremy Howard, who has always advocated for development in REPL environments and built a fantastic community, FastAI.
REPL requires a deep understanding of the language. People who haven’t learned how to use the REPL don’t even know what they are missing.
Right now, they are working on a platform that integrates AI with a REPL environment.
References
- REPL-Driven Development and Learning Velocity by Eric Normand.
- REPL Driven Design by Robert C. Martin (Uncle Bob)