REPL Mode¶
The REPL (Read-Eval-Print Loop) is an interactive mode where you can execute code line-by-line, experiment with ideas, and maintain state across commands.
Starting the REPL¶
Simply run run without arguments. By default, it starts in Python mode:
You're now in the REPL! Type :help to see available commands.
Quick Example¶
$ run
run universal REPL. Type :help for commands.
>>> :py
switched to python
python>>> x = 10
python>>> y = 20
python>>> x + y
30
python>>> def greet(name):
... return f"Hello, {name}!"
python>>> greet("World")
'Hello, World!'
python>>> :exit
Goodbye!
Key Features¶
Stateful Sessions¶
Variables and functions persist across commands:
Multi-Language Support¶
Switch between languages instantly:
Import/Require Persists¶
Imports and requires stay loaded:
Quick Experimentation¶
Perfect for testing snippets:
Basic Usage¶
Switching Languages¶
Use the :lang command or shortcuts:
# Full command
>>> :lang python
switched to python
# Or use shortcuts
>>> :py
switched to python
>>> :js
switched to javascript
>>> :rust
switched to rust
>>> :go
switched to go
Available Shortcuts¶
| Shortcut | Language |
|---|---|
:py | Python |
:js | JavaScript |
:ts | TypeScript |
:rust | Rust |
:go | Go |
:c | C |
:cpp | C++ |
:java | Java |
:rb | Ruby |
:bash | Bash |
:lua | Lua |
:php | PHP |
See all shortcuts with :languages.
Listing Supported Languages¶
This displays a list of all languages that the run tool supports. Note that this list shows the languages supported by run, not which language runtimes are actually installed on your system.
Getting Help¶
>>> :help
Commands:
:help Show this help message
:languages List available languages
:lang <id> Switch to language <id>
:detect on|off Enable or disable auto language detection
:reset Reset the current language session
:load <path> Execute a file in the current language
:exit, :quit Leave the REPL
Any language id or alias works as a shortcut, e.g. :py, :cpp, :csharp, :php.
Working with State¶
Python Example¶
python>>> data = {"name": "Alice", "age": 30}
python>>> data["city"] = "Paris"
python>>> data
{'name': 'Alice', 'age': 30, 'city': 'Paris'}
python>>> def process(d):
... return {k: v for k, v in d.items() if isinstance(v, str)}
python>>> process(data)
{'name': 'Alice', 'city': 'Paris'}
JavaScript Example¶
javascript>>> let users = []
javascript>>> users.push({name: 'Alice', age: 30})
javascript>>> users.push({name: 'Bob', age: 25})
javascript>>> users
[ { name: 'Alice', age: 30 }, { name: 'Bob', age: 25 } ]
javascript>>> users.filter(u => u.age > 26)
[ { name: 'Alice', age: 30 } ]
Rust Example¶
rust>>> let mut count = 0;
rust>>> count += 1;
rust>>> count
1
rust>>> fn double(x: i32) -> i32 { x * 2 }
rust>>> double(count)
2
Loading Files¶
Execute a file in your current session:
The file is executed in the current session, making its functions available.
Resetting State¶
Clear the current session:
python>>> x = 100
python>>> x
100
python>>> :reset
session for 'python' reset
python>>> x
NameError: name 'x' is not defined
Auto-Detection¶
Control automatic language detection:
>>> :detect on
auto-detect enabled
>>> print('hello') # Auto-detects as Python
hello
>>> :detect off
auto-detect disabled
>>> console.log('hello') # Stays in current language
Multi-Line Input¶
Some languages support multi-line input:
Python¶
python>>> def fibonacci(n):
... if n <= 1:
... return n
... return fibonacci(n-1) + fibonacci(n-2)
python>>> [fibonacci(i) for i in range(10)]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
JavaScript¶
javascript>>> function factorial(n) {
... if (n <= 1) return 1;
... return n * factorial(n-1);
... }
javascript>>> factorial(5)
120
Expressions vs Statements¶
Python¶
Expressions automatically print their value:
Statements don't:
JavaScript¶
Use the last expression as return value:
javascript>>> 2 + 2
4
javascript>>> "hello".toUpperCase()
'HELLO'
javascript>>> [1, 2, 3].map(x => x * 2)
[ 2, 4, 6 ]
Practical Examples¶
Data Exploration¶
python>>> import json
python>>> import urllib.request
python>>> url = "https://api.github.com/repos/Esubaalew/run"
python>>> response = urllib.request.urlopen(url)
python>>> data = json.loads(response.read())
python>>> data['name']
'run'
python>>> data['stargazers_count']
42
Algorithm Testing¶
python>>> def bubble_sort(arr):
... n = len(arr)
... for i in range(n):
... for j in range(0, n-i-1):
... if arr[j] > arr[j+1]:
... arr[j], arr[j+1] = arr[j+1], arr[j]
... return arr
python>>> bubble_sort([64, 34, 25, 12, 22, 11, 90])
[11, 12, 22, 25, 34, 64, 90]
Quick Calculations¶
python>>> import statistics
python>>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
python>>> statistics.mean(data)
5.5
python>>> statistics.median(data)
5.5
python>>> statistics.stdev(data)
3.0276503540974917
Prototyping APIs¶
javascript>>> class User {
... constructor(name, email) {
... this.name = name;
... this.email = email;
... }
... greet() {
... return `Hello, I'm ${this.name}`;
... }
... }
javascript>>> let user = new User('Alice', 'alice@example.com')
javascript>>> user.greet()
"Hello, I'm Alice"
Tips & Tricks¶
1. Use Tab Completion¶
Some languages support tab completion (depends on their REPL):
2. Check Documentation¶
3. Quick Debugging¶
python>>> def buggy_function(x):
... print(f"Debug: x = {x}")
... return x * 2
python>>> buggy_function(5)
Debug: x = 5
10
4. Save Snippets¶
Save useful snippets to files and :load them:
5. Switch Languages to Compare¶
>>> :py
python>>> sorted([3, 1, 4, 1, 5])
[1, 1, 3, 4, 5]
>>> :js
javascript>>> [3, 1, 4, 1, 5].sort((a,b) => a-b)
[ 1, 1, 3, 4, 5 ]
>>> :rust
rust>>> let mut v = vec![3,1,4,1,5]; v.sort(); v
[1, 1, 3, 4, 5]
Exiting the REPL¶
Common Issues¶
Issue: Changes Not Persisting¶
Problem: Variables disappear between commands.
Solution: Make sure you're not switching languages or resetting:
python>>> x = 10
python>>> :go # Switch language
go>>> # x is not available here (different language)
python>>> :py # Back to Python
python>>> x # But x is gone (new session)
Issue: Syntax Errors¶
Problem: Multi-line input isn't recognized.
Solution: Some languages need explicit continuation:
Issue: Import Not Found¶
Problem: Module import fails.
Solution: Ensure the module is installed in the language's environment:
# Exit REPL and install
$ pip install requests
# Then use in REPL
$ run
>>> :py
python>>> import requests
Advanced Usage¶
Scripting the REPL¶
Pipe commands to the REPL:
Combining with Shell¶
Persisting Session State¶
State persists within a language session until :reset or language change:
python>>> import sys
python>>> data = [1, 2, 3]
# This state persists
python>>> :rust
# State is saved
python>>> :py
# Back to Python, state is restored
python>>> data
[1, 2, 3]
Next Steps¶
REPL Commands → Stateful Sessions → Language-Specific Behavior →