Skip to content
The Chat Archive
o3-2025-04-16· OpenAI LMArena Human Preference 140K

what programming languages have very nice cli repls with the ability to save and reload…

  1. 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.

  2. 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 fuss

    For 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.core brings 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)
    hi
    

    Why 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 (or SystemCompiler 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 with q() and answer “yes”.
    Restores on start if .RData is present or via load("file.RData").
    🔄 Functions are first-class objects; just type hello <- 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 launch
    

    or

    >>> import dill, sys
    >>> dill.dump_session('sess.pkl')
    # later
    >>> dill.load_session('sess.pkl')
    

    🔄 Just re-def the 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-image at the listener; run later with factor -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, …}] or Save["state.m", $Context].
    🔄 SetDelayed/Set can be re-run; Get["state.m"] restores.


    9. Julia 1.9+

    Julia lets you redefine methods freely, and package-images are coming:

    🛠️ Revise.jl handles 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

    LanguageSave whole memory?One-line redefine?Out-of-the-box tools
    Common Lisp✅ Image (.core)✅ defunSLIME/Sly, REPL
    Smalltalk✅ Image (.img)✅ method compilePharo, 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✅ Setmath CLI / notebook
    Julia⚠️ Serialisation✅ Revise.jlJulia REPL
    Scala (Ammonite)⚠️ Serialize✅ defAmmonite

    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 with clj-snapshots, though not bullet-proof).

    Happy hacking & time-traveling through your REPL sessions!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.