summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-03-29 22:29:32 +0000
committerRich Hickey <richhickey@gmail.com>2008-03-29 22:29:32 +0000
commit540e3dcaa17c6c7e5a03f055c9aecbdd7050720d (patch)
tree4c5f345fb40db6c53b5b44af782870e104c5c29d /src
parent1e31c582bfa5fbf73285efdfcf5448efc3a3935a (diff)
got rid of implement, added docs
Diffstat (limited to 'src')
-rw-r--r--src/boot.clj73
-rw-r--r--src/inspector.clj22
-rw-r--r--src/xml.clj19
3 files changed, 64 insertions, 50 deletions
diff --git a/src/boot.clj b/src/boot.clj
index e67cd0dd..e26a0947 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -53,23 +53,28 @@
rest (fn rest [x] (. clojure.lang.RT (rest x))))
(def
- #^{:doc "Same as (first (rest x))"}
+ #^{:doc "Same as (first (rest x))"
+ :arglists '([x])}
second (fn second [x] (first (rest x))))
(def
- #^{:doc "Same as (first (first x))"}
+ #^{:doc "Same as (first (first x))"
+ :arglists '([x])}
ffirst (fn ffirst [x] (first (first x))))
(def
- #^{:doc "Same as (rest (first x))"}
+ #^{:doc "Same as (rest (first x))"
+ :arglists '([x])}
rfirst (fn rfirst [x] (rest (first x))))
(def
- #^{:doc "Same as (first (rest x))"}
+ #^{:doc "Same as (first (rest x))"
+ :arglists '([x])}
frest (fn frest [x] (first (rest x))))
(def
- #^{:doc "Same as (rest (rest x))"}
+ #^{:doc "Same as (rest (rest x))"
+ :arglists '([x])}
rrest (fn rrest [x] (rest (rest x))))
(def
@@ -166,11 +171,11 @@
(def
- #^{:doc "(defn name doc-string? attr-map? [params*] body) or (defn
- name doc-string? attr-map? ([params*] body)+ attr-map?) Same
- as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ]
- exprs*)+)) with any doc-string or attrs added to the var
- metadata"}
+ #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
+ name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
+ to the var metadata"
+ :arglists '([name doc-string? attr-map? [params*] body]
+ [name doc-string? attr-map? ([params*] body)+ attr-map?])}
defn (fn defn [name & fdecl]
(let [m (if (string? (first fdecl))
{:doc (first fdecl)}
@@ -246,7 +251,9 @@
#^{:doc "Like defn, but the resulting function name is declared as a
macro and will be used as a macro by the compiler when it is
- called."}
+ called."
+ :arglists '([name doc-string? attr-map? [params*] body]
+ [name doc-string? attr-map? ([params*] body)+ attr-map?])}
defmacro (fn [name & args]
(list 'do
(cons `defn (cons name args))
@@ -973,7 +980,8 @@
(def
#^{:tag Boolean
:doc "Returns false if (pred x) is logical true for every x in
- coll, else true."}
+ coll, else true."
+ :arglists '([pred coll])}
not-every? (comp not every?))
(defn some
@@ -986,7 +994,8 @@ not-every? (comp not every?))
(def
#^{:tag Boolean
:doc "Returns false if (pred x) is logical true for any x in coll,
- else true."}
+ else true."
+ :arglists '([pred coll])}
not-any? (comp not some))
(defn map
@@ -1281,34 +1290,6 @@ not-every? (comp not every?))
array [& items]
(into-array items))
-(defn
-make-proxy [classes method-map]
- (. java.lang.reflect.Proxy
- (newProxyInstance (.. Thread (currentThread) (getContextClassLoader))
- (into-array classes)
- (new clojure.lang.ProxyHandler method-map))))
-
-(defmacro implement
- "f => (name [args+] body)
-
- Deprecated - use proxy.
- Expands to code which creates a instance of a class that implements
- the named interface(s) by calling the supplied fns. The interface
- names must be valid class names of interface types. If a method is
- not provided for a non-void-returning interface method, an
- UnsupportedOperationException will be thrown should it be called.
- Method fns are closures and can capture the environment in which
- implement is called."
- [interfaces & fs]
- `(make-proxy
- ~interfaces
- ~(loop [fmap {} fs fs]
- (if fs
- (recur (assoc fmap (name (ffirst fs))
- (cons `fn (rfirst fs)))
- (rest fs))
- fmap))))
-
(defn pr
"Prints the object(s) to the output stream that is the current value
of *out*. Prints the object(s), separated by spaces if there is
@@ -1483,6 +1464,7 @@ make-proxy [classes method-map]
#^{:private true}
def-aset [name method coerce]
`(defn ~name
+ {:arglists '([~'array ~'idx ~'val] [~'array ~'idx ~'idx2 & ~'idxv])}
([array# idx# val#]
(. Array (~method array# idx# (~coerce val#)))
val#)
@@ -2273,4 +2255,13 @@ make-proxy [classes method-map]
v))
coll (range (count coll)))
(map #(if-let e (find smap %) (val e) %) coll)))
+
+(defmacro dosync
+ "Runs the exprs (in an implicit do) in a transaction that encompasses
+ exprs and any nested calls. Starts a transaction if none is already
+ running on this thread. Any uncaught exception will abort the
+ transaction and flow out of dosync. The exprs may be run more than
+ once, but any effects on Refs will be atomic."
+ [& exprs]
+ `(sync nil ~@exprs))
\ No newline at end of file
diff --git a/src/inspector.clj b/src/inspector.clj
index f0d829aa..2e24cccb 100644
--- a/src/inspector.clj
+++ b/src/inspector.clj
@@ -48,7 +48,7 @@
(nth (seq m) index))
(defn tree-model [data]
- (implement [TreeModel]
+ (proxy [TreeModel] []
(getRoot [] data)
(addTreeModelListener [treeModelListener])
(getChild [parent index]
@@ -69,7 +69,7 @@
colcnt (count row1)
cnt (count data)
vals (if (instance? clojure.lang.IPersistentMap row1) vals identity)]
- (implement [TableModel]
+ (proxy [TableModel] []
(addTableModelListener [tableModelListener])
(getColumnClass [columnIndex] Object)
(getColumnCount [] colcnt)
@@ -83,20 +83,28 @@
(isCellEditable [rowIndex columnIndex] false)
(removeTableModelListener [tableModelListener]))))
-(defn inspect-tree [data]
+(defn inspect-tree
+ "creates a graphical (Swing) inspector on the supplied hierarchical data"
+ [data]
(doto (new JFrame "Clojure Inspector")
(add (new JScrollPane (new JTree (tree-model data))))
(setSize 400 600)
(setVisible true)))
-(defn inspect-table [data]
+(defn inspect-table
+ "creates a graphical (Swing) inspector on the supplied regular
+ data, which must be a sequential data structure of data structures
+ of equal length"
+ [data]
(doto (new JFrame "Clojure Inspector")
(add (new JScrollPane (new JTable (table-model data))))
(setSize 400 600)
(setVisible true)))
-;(export '(inspect-table inspect-tree))
+(comment
-;(inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]})
-;(inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]])
+(load-file "src/inspector.clj")
+(inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]})
+(inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]])
+) \ No newline at end of file
diff --git a/src/xml.clj b/src/xml.clj
index abc3844c..7ad8198c 100644
--- a/src/xml.clj
+++ b/src/xml.clj
@@ -31,7 +31,7 @@
(some (complement #(. Character (isWhitespace %))) (str *sb*)))
(set! *current* (push-content *current* (str *sb*)))))]
(new clojure.lang.XMLHandler
- (implement [ContentHandler]
+ (proxy [ContentHandler] []
(startElement [uri local-name q-name #^Attributes atts]
(let [attrs (fn [ret i]
(if (neg? i)
@@ -61,12 +61,27 @@
(let [#^StringBuilder sb *sb*]
(. sb (append ch start length))
(set! *state* :chars))
- nil)))))
+ nil)
+ (setDocumentLocator [locator])
+ (startDocument [])
+ (endDocument [])
+ (startPrefixMapping [prefix uri])
+ (endPrefixMapping [prefix])
+ (ignorableWhitespace [ch start length])
+ (processingInstruction [target data])
+ (skippedEntity [name])
+ ))))
(defn startparse-sax [s ch]
(.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch)))
(defn parse
+ "Parses and loads the source s, which can be a File, InputStream or
+ String naming a URI. Returns a tree of the xml/element struct-map,
+ which has the keys :tag, :attrs, and :content. and accessor fns tag,
+ attrs, and content. Other parsers can be supplied by passing
+ startparse, a fn taking a source and a ContentHandler and returning
+ a parser"
([s] (parse s startparse-sax))
([s startparse]
(binding [*stack* nil