Starting the REPL
To start the REPL, runwalrus without any file argument:
Basic usage
Type Walrus code at the prompt and press Enter to execute:Features
Expression evaluation
The REPL evaluates expressions immediately:Variable persistence
Variables defined in the REPL persist across statements:Function definitions
Define and call functions interactively:Struct definitions
Create and use structs:Import modules
Load standard library modules:REPL state
The REPL maintains state throughout your session:- Variables: All
letdeclarations persist - Functions: Defined functions remain available
- Structs: Struct definitions are preserved
- Imports: Modules are loaded once and cached
Execution mode
The REPL uses the tree-walking interpreter by default for immediate feedback. This provides:- Instant execution without compilation
- Direct AST interpretation
- Simplified debugging output
Limitations
Single-line input only
Currently, the REPL only supports single-line input. Multi-line constructs must be entered on one line:No command history
The REPL does not currently support:- Arrow key navigation through history
- Tab completion
- Line editing shortcuts
Empty lines
Empty input is ignored:Debugging in REPL
Enable debug logging when starting the REPL:--verbose: General information--debug: Detailed debug output--trace: Complete execution trace
Use cases
Quick calculations
Testing algorithms
String manipulation
Data structure exploration
Function experimentation
Learning the language
The REPL is excellent for:- Testing syntax
- Understanding operators
- Exploring built-in functions
- Experimenting with language features
Exiting the REPL
To exit the REPL:- Press
Ctrl+Cto interrupt - Press
Ctrl+D(EOF) to exit gracefully - Use
sys.exit()from the standard library: