Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I clean the repl?

I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done?

like image 421
Belun Avatar asked Sep 03 '10 13:09

Belun


People also ask

How do you clear a Scala REPL?

Implementing it wouldn't be hard, either! I believe Ctrl + L should be able to clear the REPL console.


2 Answers

If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) :

(map #(ns-unmap *ns* %) (keys (ns-interns *ns*))) 

or

(ns myutil) (defn ns-clean        "Remove all internal mappings from a given name space or the current one if no parameter given."    ([] (ns-clean *ns*))     ([ns] (map #(ns-unmap ns %) (keys (ns-interns ns))))) (ns mytest)  ... make loads of junk ...  (myutil/ns-clean)  ... great!!! I can now make all new junk ...  

It does not claim to give you a squeaky clean namespace, just one with less of the junk which usually accumulates in a typical repl session.

Use with caution : do not pull the rug from under your feet!

like image 122
Peter Tillemans Avatar answered Nov 09 '22 06:11

Peter Tillemans


If you are running the repl through a terminal window (eg: Terminal.app on MacOS or xterm/aterm/urxvt etc on linux) then you can type Control-L and it should clear the terminal window and give you a new repl prompt. However all macros/atoms you previously defined are still going to be in memory, so this is just a "Cosmetic" clear.

like image 24
Brian Gianforcaro Avatar answered Nov 09 '22 06:11

Brian Gianforcaro