Clojure
user=> ,?
Comma Commands
,s Show the most recent exception's stack trace
,r Show the most recent object returned by read
,e Show the most recent object returned by eval
,h Show this help
,? Show this help
user=> (conj '(1 2 3) [4 5 6])
([4 5 6] 1 2 3)
user=> ,r
(conj (quote (1 2 3)) [4 5 6])
user=> ,e
([4 5 6] 1 2 3)
user=> ,s
no exceptions yet!
user=> (/ 1 0)
java.lang.ArithmeticException: Divide by zero
user=> ,s
java.lang.ArithmeticException: Divide by zero
at clojure.lang.Numbers.divide(Numbers.java:142)
at user.eval__2288.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:3850)
at clojure.lang.Repl.main(Repl.java:95)
user=>
I've enclosed a patch to Repl.java. Comments and suggestions are welcome.
I've enclosed a patch to Repl.java. Comments and suggestions arewelcome.
This is really neat addition for the repl.
Thanks Steve.
For some reason I can't see the patch so I haven't had a chance to try it yet.
I suggest using keywords for commands. They evaluate to themselves and
there is no purpose to entering them at the repl otherwise (other than
demonstrating that keywords evaluate to themselves, I guess). Commas
violate the read/data rules and are ugly.
More important, I don't see a strong case for commands yet. Commands
for printing the last object read and the last evaluated value and
last stack trace are substantially less useful than vars that evaluate
to those values. While * isn't available, *1 *2 *3 *ex (and various
other possibilities) are.
Clojure
user=> (+ 3 4)
7
user=> (+ 1 5)
6
user=> (* *1 *2)
42
user=> *r
(* *1 *2)
user=> *e
nil
user=> egan
java.lang.Exception: Unable to resolve symbol: egan in this context
user=> *e
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:0: Unable to resolve symbol: egan in this context
user=> (.printStackTrace *e)
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:0: Unable to resolve symbol: egan in this context
at clojure.lang.Compiler.analyze(Compiler.java:3713)
at clojure.lang.Compiler.analyze(Compiler.java:3671)
at clojure.lang.Compiler.eval(Compiler.java:3895)
at clojure.lang.Repl.main(Repl.java:88)
Caused by: java.lang.Exception: Unable to resolve symbol: egan in this context
at clojure.lang.Compiler.resolveIn(Compiler.java:4015)
at clojure.lang.Compiler.resolve(Compiler.java:3972)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:3955)
at clojure.lang.Compiler.analyze(Compiler.java:3686)
... 3 more
nil
user=>
Parth and Rich: Thanks very much for your comments and suggestions.
Thanks Steve,
I'm willing to add this with a couple of changes:
You can def the vars in boot.clj, with no roots. Please provide doc
strings.
Lose *r, it's not really useful
In the Repl, push bindings for them (where ns is pushed), then use
star1.set(...) etc to update the per-thread binding. As written, these
vars can't be used by more than one repl/thread without conflict.
I added support for *1 *2 *3 in my fork of swank-clojure (for emacs/
slime), http://github.com/mikehinchey/swank-clojure.
I did one thing different which is to not reset the vars if the eval
is one of the vars themselves. Rich noted most CL repls don't do
this, but it seems useful to me. Thoughts?