what programming languages have very nice cli repls with the ability to save and reload…
- User
what programming languages have very nice cli repls with the ability to save and reload the total state easily? I need to be able to override or chamge existing functions and variables.
- Assistant
Below is a short-list of languages whose command-line REPLs are especially good at
• redefining functions/vars on the fly
• dumping the whole in-memory “world” (or a big chunk of it) to disk
• restoring that world in a later REPL session with minimal fussFor each one I note
🛠️ How you normally save/restore the session
🔄 Whether hot–redefinition is 1st-class
⌨️ A quick REPL snippet that shows how it feels
1. Common Lisp (SBCL, CCL, etc.)
🛠️
(save-lisp-and-die "myimage.core")dumps an entire image;
sbcl --core myimage.corebrings it back.
🔄 Redefinition is built-in: just evaluate a new(defun …)or(defvar …).
⌨️CL-USER> (defun hello () (format t "hi~%")) HELLO CL-USER> (save-lisp-and-die "demo.core") # restart later $ sbcl --core demo.core CL-USER> (hello) hiWhy it’s nice: zero ceremony, and images can be tiny (a few MB) or full app snapshots.
2. Smalltalk (Pharo/Squeak CLI headless image)
Although often used with a GUI, you can run a headless image from the shell.
🛠️
Smalltalk saveImageAs: 'new.img'
🔄 All code/data live in the image; re-defining a method is one click (orSystemCompiler source: ...).
⌨️Object subclass: #Greeter instanceVariableNames: '' Greeter >> greet Transcript show: 'hello'. Smalltalk saveImageAs: 'greeter.img'.Run later:
$ pharo greeter.img eval "Greeter new greet"→ hello
3. R
🛠️
save.image()or simply exit withq()and answer “yes”.
Restores on start if.RDatais present or viaload("file.RData").
🔄 Functions are first-class objects; just typehello <- function() …again.
⌨️> x <- pi > hello <- function() cat("hi\n") > save.image("mysession.RData") # later $ R > load("mysession.RData"); hello() hi
4. Python + IPython/ptpython (using dill/pickle,
%store, or shelve)Pure CPython can’t dump the whole VM in one go, but in practice:
🛠️ In IPython:
In [1]: import dill, atexit, builtins, sys, os, pickle In [2]: %store my_big_object In [3]: %store -r # on next launchor
>>> import dill, sys >>> dill.dump_session('sess.pkl') # later >>> dill.load_session('sess.pkl')🔄 Just re-
defthe function; IPython even has%autoreload.
⬇️ Limitation: objects that can’t be pickled (file handles, C-libs) won’t survive.
5. Guile Scheme
🛠️
(save-module-excursion (lambda () …))or(primitive-load-path '(...)); more commonly,(save-run(,@command-line))dumps an ELF image. 🔄(define (foo) …)` again → foo is swapped live.
6. Factor
A modern stack-language with an image-based VM.
🛠️
save-imageat the listener; run later withfactor -i=my.image.
🔄: foo ( x -- x ) dup . ;then redefine the word later—immediately active.
7. Forth (gforth, lxforth)
🛠️
save-system mycore
🔄: word ... ;again → overwritten.
Extremely small footprints; good when you want embedded-style snapshots.
8. Mathematica / Wolfram Language (CLI is
math)🛠️
DumpSave["file.mx", {sym1, sym2, …}]orSave["state.m", $Context].
🔄SetDelayed/Setcan be re-run;Get["state.m"]restores.
9. Julia 1.9+
Julia lets you redefine methods freely, and package-images are coming:
🛠️
Revise.jlhandles hot-redefinition; for snapshotting:Serialization.serialize("snapshot.jls", workspace_obj). Whole-session checkpointing is still young but improves via JLSO/JLD2.
10. Ammonite (Scala)
Ammonite-REPL has
@repl.save("file")/@repl.load("file").
Redefinitions work (def foo = ...again), but JVM objects must be Serializable.
Cheat-sheet comparison
Language Save whole memory? One-line redefine? Out-of-the-box tools Common Lisp ✅ Image (.core) ✅ defunSLIME/Sly, REPL Smalltalk ✅ Image (.img) ✅ method compile Pharo, Squeak R ✅ .RData ✅ overwrite <-R console, RStudio Python+IPython ⚠️ Pickle/dill ✅ defIPython, ptpython Factor/Forth ✅ Image/core ✅ : redefineFactor, gforth Guile Scheme ✅ ELF image ✅ defineGuile REPL Mathematica ✅ .mx / .m ✅ Set math CLI / notebook Julia ⚠️ Serialisation ✅ Revise.jl Julia REPL Scala (Ammonite) ⚠️ Serialize ✅ def Ammonite Key points to help you choose
• Want the most “save it, quit, restore tomorrow exactly where I left off”?
→ Common Lisp, Smalltalk, Factor.• Need open-source, no GUI, easy OS packaging?
→ SBCL (Common Lisp) or Guile Scheme.• Already in the scientific/data world?
→ R or Python/IPython (with dill).• JVM ecosystem but still image-like?
→ Ammonite (or Clojure withclj-snapshots, though not bullet-proof).Happy hacking & time-traveling through your REPL sessions!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.