On Fri, Dec 12, 2008 at 11:37 PM, Chouser <chou...@gmail.com> wrote:
>
> I've added updated versions of 'show' and 'source' to a new lib named
> clojure.contrib.repl-utils
>
> 'show' is for exploring classes at the REPL.  What's new is that it
> now displays the modifiers of the class and the parameter types for
> each method.
>
> 'source' tries to display the Clojure source for any Var.  It now
> sports more robust logic for finding the source file and determining
> the end of the Var's definition.
>
> user=> (show 1/2)
> ===  public clojure.lang.Ratio  ===
> [ 0] <init> (BigInteger,BigInteger)
> [ 1] denominator : BigInteger
> [ 2] numerator : BigInteger
> [ 3] byteValue : byte ()
> [ 4] compareTo : int (Object)
> [ 5] doubleValue : double ()
> [ 6] equals : boolean (Object)
> [ 7] floatValue : float ()
> [ 8] getClass : Class ()
> [ 9] hashCode : int ()
> [10] intValue : int ()
> [11] longValue : long ()
> [12] notify : void ()
> [13] notifyAll : void ()
> [14] shortValue : short ()
> [15] toString : String ()
> [16] wait : void ()
> [17] wait : void (long)
> [18] wait : void (long,int)
>
> Note that 'show' takes instances or classes.  Members are sorted by
> kind: static fields, static methods, constructors, instance fields,
> instance methods.  Note that parameter package names and method
> modifiers are not displayed for brevity.  For complete details on a
> member, append its number to the call:
>
> user=> (show 1/2 3)
> #<Method public byte java.lang.Number.byteValue()>
>
> This actually returns the method itself, and so can be used to
> construct more complex introspection expressions:
>
> user=> (show (.getType (show 1/2 1)))
> ===  public java.math.BigInteger  ===
> [ 0] static ONE : BigInteger
> [ 1] static TEN : BigInteger
> [ 2] static ZERO : BigInteger
> ...etc...
>
> Use of 'source' couldn't be simpler:
> user=> (source filter)
> (defn filter
>  "Returns a lazy seq of the items in coll for which
>  (pred item) returns true. pred must be free of side-effects."
>  [pred coll]
>    (when (seq coll)
>      (if (pred (first coll))
>        (lazy-cons (first coll) (filter pred (rest coll)))
>        (recur pred (rest coll)))))
> nil
>
> user=> (source clojure.zip/node)
> (defn node
>  "Returns the node at loc"
>  [loc] (loc 0))
> nil

I just updated to the latest version of clojure-contrib.  show works
for me, but source doesn't. Here's what I did.

(require 'clojure.contrib.repl-utils)
(show 1/2) ; gives the output you show above
(source filter)
java.lang.Exception: Unable to resolve symbol: source in this context
(NO_SOURCE_FILE:3)

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to