summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-09-07 20:45:08 +0000
committerRich Hickey <richhickey@gmail.com>2007-09-07 20:45:08 +0000
commit3be7356fb858fd68d92471ad46ee7e9a4378d5a7 (patch)
tree656b1a58be4117059e316a883d8a779e6e33d362 /src
parent236855e91b23ee35947233d8d4da6ab5c8a760f0 (diff)
more functions
Diffstat (limited to 'src')
-rw-r--r--src/boot.clj45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/boot.clj b/src/boot.clj
index dc659c92..bfac2270 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -65,14 +65,17 @@
(list 'let (vector gor x)
(list 'if gor gor (cons 'or rest))))))
-(defn apply
- ([f & args]
- (let [spread (fn [arglist]
- (cond
- (nil? arglist) nil
- (nil? (rest arglist)) (first arglist)
- :else (cons (first arglist) (thisfn (rest arglist)))))]
- (. f (applyTo (spread args))))))
+(defn spread [arglist]
+ (cond
+ (nil? arglist) nil
+ (nil? (rest arglist)) (first arglist)
+ :else (cons (first arglist) (thisfn (rest arglist)))))
+
+(defn apply [f & args]
+ (. f (applyTo (spread args))))
+
+(defn list* [& args]
+ (spread args))
(defn +
([] 0)
@@ -156,7 +159,31 @@
(defmacro locking [x & body]
(let [gsym (gensym)]
- (list 'let (vector gsym x)
+ (list 'let [gsym x]
(list 'try-finally
(cons 'do (cons (list 'monitor-enter gsym) body))
(list 'monitor-exit gsym)))))
+
+(defmacro delay [& body]
+ (list '. 'clojure.lang.Delay (list 'new (list* 'fn [] body))))
+
+(defmacro lazy-cons [x & body]
+ (list '. 'clojure.lang.FnSeq (list 'new x (list* 'delay body))))
+
+(defn concat
+ ([] nil)
+ ([x & xs]
+ (cond
+ (nil? xs) x
+ (nil? x) (recur (first xs) (rest xs))
+ :else (lazy-cons (first x) (apply concat (rest x) xs)))))
+
+(defn andf [& args]
+ (if (nil? (rest args))
+ (first args)
+ (and (first args) (recur (rest args)))))
+
+(defn orf [& args]
+ (if (nil? args)
+ nil
+ (or (first args) (recur (rest args))))) \ No newline at end of file