Return to Snippet

Revision: 14460
at June 4, 2009 15:44 by narkisr


Initial Code
user=> (use 'clojure.contrib.repl-utils)

; shows the source of the filter method
user=> (source filter)
(defn filter
  "Returns a lazy sequence of the items in coll for which
  (pred item) returns true. pred must be free of side-effects."
  [pred coll]
  (let [step (fn [p c]
                 (when-let [s (seq c)]
                   (if (p (first s))
                     (cons (first s) (filter p (rest s)))
                     (recur p (rest s)))))]
    (lazy-seq (step pred coll))))

; shows all the methods of Clojure ratio type
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] decimalValue : BigDecimal ()
[ 6] decimalValue : BigDecimal (MathContext)
[ 7] doubleValue : double ()
[ 8] equals : boolean (Object)
[ 9] floatValue : float ()
[10] getClass : Class ()
[11] hashCode : int ()
[12] intValue : int ()
[13] longValue : long ()
[14] notify : void ()
[15] notifyAll : void ()
[16] shortValue : short ()
[17] toString : String ()
[18] wait : void ()
[19] wait : void (long)
[20] wait : void (long,int)

Initial URL

                                

Initial Description
Clojure contribe repl-utils offers two functions for locating the source code of functions & the method of types (http://groups.google.com/group/clojure/browse_thread/thread/77f95518fcfc8a08/5de8ef8ff8f3b3bd?lnk=gst&q=source#5de8ef8ff8f3b3bd).

Initial Title
Viewing source & type methods in Clojure REPL

Initial Tags

                                

Initial Language
Lisp