Language-Specific REPL Behavior¶
Different languages have different REPL behaviors. This guide explains how each language handles sessions.
Python¶
Session State¶
Python accumulates code in a temporary module:
All persist across commands.
Expression Evaluation¶
Expressions automatically print their repr():
Statements don't print:
Multi-line Input¶
Use ... for continuation:
python>>> def factorial(n):
... if n <= 1:
... return 1
... return n * factorial(n-1)
python>>> factorial(5)
120
JavaScript¶
Session State¶
Variables and functions persist:
javascript>>> let count = 0
javascript>>> function increment() { count++; return count; }
javascript>>> increment()
1
javascript>>> increment()
2
Expression Evaluation¶
Last expression is returned:
Rust¶
Session State¶
Rust compiles snippets incrementally:
Main Function¶
Rust automatically wraps code in main():
Compilation¶
Each snippet is compiled, so errors are caught:
Go¶
Session State¶
Go maintains state across commands:
Package Main¶
Automatically includes package main:
Bash¶
Session State¶
Variables and functions persist:
Script Rewrites¶
Session script is rewritten on each evaluation.
C/C++¶
Session State¶
Code snippets are accumulated:
Compilation¶
Compiled on each command:
Compiled vs Interpreted¶
Interpreted Languages¶
- Python, JavaScript, Ruby, Bash, etc.
- Instant evaluation
- No compilation step
- Session maintained in memory
Compiled Languages¶
- Rust, Go, C, C++, etc.
- Compilation on each command
- Temporary binaries created
- Session reconstructed from history
Tips by Language¶
Python¶
# Use help()
python>>> help(str.split)
# Check type
python>>> type([1, 2, 3])
<class 'list'>
# List attributes
python>>> dir({})
JavaScript¶
# Check prototype
javascript>>> Object.getPrototypeOf([])
# Type checking
javascript>>> typeof 42
'number'