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
; create attributes p and q, where p is unique identity | |
(d/transact edb1 {:tx-data [{:db/ident :p :db/cardinality :db.cardinality/one :db/valueType :db.type/keyword :db/unique :db.unique/identity}]}) | |
=> | |
(d/transact edb1 {:tx-data [{:db/ident :q :db/cardinality :db.cardinality/one :db/valueType :db.type/keyword}]}) | |
=> | |
; now add a datum | |
(d/transact edb1 {:tx-data [{:p :a1 :q :x}]}) |
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 defns-- | |
"Makes all private fns | |
in the namespace with the | |
given name public" | |
[namespace-name] | |
(doseq [[_ v] | |
(filter | |
(fn [[_ x]] | |
(if (var? x) (-> x meta :ns ns-name #{namespace-name}) false)) | |
(ns-map namespace-name))] |
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
{:paths ["."] :deps {robert/hooke {:mvn/version "1.3.0"} | |
com.taoensso/tufte {:mvn/version "2.4.5"}}} |
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
(let [eval-right? clojure.core/eval] (intern 'clojure.core 'eval (fn [form] (if (= 'right? (last form)) (eval-right? (butlast form)) 'right?)))) |
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 put [f x] (let [is-str? (char? (first x)) sx (apply str x)] (cond (map? f) (into {} (map vec (partition 2 (if (even? (count x)) x (conj x nil))))) (vector? f) (if is-str? (conj f sx) (into f x)) (list? f) (if is-str? (cons sx f) (concat f x)) (set? f) (if is-str? #{sx} (into f x))))) | |
(defn structure [s f] (mapv (fn [b a] (if (empty? b) (put b a) (let [r (structure a b)] (if (vector? b) (vec r) r)))) f (partition-all (int (/ (count s) (count f))) s))) | |
(structure (range 32) [[[] #{}] [#{} [] []]]) | |
=> | |
[[[0 1 2 3 4 5 6 7] #{15 13 12 11 9 14 10 8}] |
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
(fn [params] | |
{ | |
:namespace-name 'a | |
:requires [] | |
:defs | |
'{ | |
x (fn [y] (str "a's " y)) | |
}}) |
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
; I was curious as to whether unrolling | |
; this use of transducers would be faster | |
; | |
; in fact it's slower | |
; we're given an array which we | |
; process using fns f, g and h | |
(defn test1-xf [^bytes data] | |
(comp |
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 mms | |
(:require | |
[clojure.math.combinatorics :as x] | |
[clojure.set :as set])) | |
(defn derive-set | |
" | |
A copy of derive for sets | |
" | |
([h a-set parent-set] |
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
; https://www.scientificamerican.com/article/is-inequality-inevitable/ | |
; https://threadreaderapp.com/thread/1210332075787608065.html | |
(defn economy-dw | |
" | |
Simulate one round of | |
random transfers of wealth | |
between the given agents' accounts | |
(a vector of initial amounts) |
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
(let [{z :x x 'y y "z" :keys [x y z] :syms [x y z] :strs [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil nil 3] | |
(let [{z :x x 'y y "z" :keys [x y z] :syms [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [nil 2 nil] | |
(let [{z :x x 'y y "z" :keys [x y z]} {:x 1 'y 2 "z" 3}] [x y z]) | |
=> [1 nil nil] | |
(let [{z :x x 'y y "z"} {:x 1 'y 2 "z" 3}] [x y z]) |