Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Clojure REPL lines

Maybe this is a newbee question, sorry if so!

Is it possible to store all lines I typed into the REPL in a file? Maybe one can configure it to do so or do this before closing the REPL session.

Thanks for your answer!

like image 511
Christian Avatar asked Mar 10 '26 14:03

Christian


2 Answers

Leiningen stores history by default when in a project:

$ lein new hello
$ cd hello
$ lein repl
user=> (+ 1 2 3)
user=> (exit)
$ cat .lein-repl-history

Boot always stores history by default:

$ boot repl
boot.user=> (+ 1 2 3)
boot.user=> (exit)
$ cat .nrepl-history
like image 74
Sam Estep Avatar answered Mar 13 '26 19:03

Sam Estep


You may use tee command line utility. See the following:

$ lein repl | tee repl-output.txt
nREPL server started on port 52576 on host 127.0.0.1 - nrepl://127.0.0.1:52576
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_66-b17
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (+ 1 2)
3
user=> (println "Hello, world!")
Hello, world!
nil
user=> Bye for now!

And after:

$ cat repl-output.txt
nREPL server started on port 52576 on host 127.0.0.1 - nrepl://127.0.0.1:52576
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_66-b17
...
...

Notice, that such method will capture all REPL output along with forms you entered.

like image 36
OlegTheCat Avatar answered Mar 13 '26 21:03

OlegTheCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!