This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rducts | |
([f aseq] (lazy-seq (rducts f (f (first aseq)) (rest aseq)))) | |
([f accum aseq] | |
(lazy-seq (cons accum (let [fs (first aseq) rs (rest aseq)] | |
(if (not (seq rs)) | |
(list (f accum fs)) | |
(rducts f (f accum fs) rs))))))) | |
(take 5 (rducts + (range))) | |
(rducts conj [1] [2 3 4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tipe [s] | |
(let [sym1 (gensym) sym2 (gensym) | |
sym3 (gensym) s12 (conj s {sym1 sym2}) | |
s1221 (conj (conj s {sym2 sym1}) s12)] | |
(if (get s12 sym1) :map | |
(if (get s12 {sym1 sym2}) :set | |
(if (= (first s1221) s12) :list :vector))))) | |
(= :map (tipe {:a 1, :b 2})) | |
(= :list (tipe (range (rand-int 20)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clojure4.core) | |
;;; Re-implement Clojure "comp" for 4Clojure problem #58 (as "komp") | |
(defn komp | |
([] (fn [n] (identity n))) | |
([fn1] (fn [& n] (apply fn1 n)) ) | |
([fn1 fn2] (fn [& n] | |
(fn1 ((fn [m] (apply fn2 m)) n)))) | |
([fn1 fn2 & fns] (fn [& n] | |
(fn1 ((fn [m] (apply (apply komp (conj fns fn2)) m )) n ))))) |
NewerOlder