On Sep 13, 1:59 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> On Sep 13, 2008, at 12:14 PM, Rich Hickey wrote:
>
> > 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.
>
> I've uploaded a patch that provides *1, *2, *3, *e, and *r. *1, *2,
> and *3 are the 3 most recent evaluated values. *r is the most recently
> read object, and *e is the most recent exception. They are all bound
> to nil initially.
>
> http://clojure.googlegroups.com/web/star-vars.patch
>
> Where a command might be useful is as a shortcut for
> "(.printStackTrace *e)". I experimented with writing the stack trace
> to a string and storing that, but when the repl prints it, it's as one
> horizontal string with embedded "\n" and \t".
>
> Here's an example of the star-vars in action:
>
> 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.
Thanks,
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---