Over a million developers have joined DZone.

Clojure REPL stores the latest results in *1, *2, *3, exception in *e

DZone's Guide to

Clojure REPL stores the latest results in *1, *2, *3, exception in *e

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

All Clojure REPL variants (nREPL, REPLy, ..) share some common characteristics, inherited from clojure.main and clojure.repl. One of them, that isn’t easy to find out (unless you read e.g. Clojure Programming) is the fact that the last three results of evaluating your code are stored in the vars *1*2, and *3. The last exception that has occured is stored in *e.


;; Inside lein repl, with the user=> prefix removed and output prefixed with ;; =>
;; => 1
;; => 2
;; => 3
;; => 4
(println "results - latest:" *1 "prev:" *2 "oldest:" *3)
;; => results - latest: 4 prev: 3 oldest: 2
;; => nil
(/ 42 0)
;; => ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:156)
(println "res" *1 "exception" *e)
;; => res nil exception #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
;; => nil

Notice that clojure.repl defines in its namespace some very useful functions and macros such as find-docdocsourceaproposdir (prints a sorted list of public vars in a ns; ex.: (dir clojure.repl)), (root-cause throwable) – check out their docs at ClojureDocs/clojure.repl.

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.


Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}