This file contains 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
;; see also https://twitter.com/thing_umbrella/status/1111427898487898113 | |
(require '[clojure.spec.alpha :as s]) | |
;; spec that ensures the keys in renames match the keys in map | |
(s/def ::rename-keys-args | |
(s/and (s/cat :map map? :renames map?) | |
(fn [{:keys [map renames]}] | |
(every? map (keys renames))))) | |
;; ok |
This file contains 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 [a 1 b]) | |
Syntax error macroexpanding clojure.core/let at (REPL:5:1). | |
[a 1 b] - failed: even-number-of-forms? at: [:bindings] spec: :clojure.core.specs.alpha/bindings |
This file contains 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
;; Datomic example code | |
;; make in memory database | |
(use '[datomic.api :only (q db) :as d]) | |
(def uri "datomic:mem://matches") | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
;; add the match attribute | |
(d/transact |
This file contains 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
;; compare to https://gist.github.com/lensgolda/13e549476fb65d3b8c2d71ca59b15937#file-test-clj | |
(require '[clojure.spec.alpha :as s]) | |
;; general domain knowledge, not buried in a test | |
(s/def ::info (s/keys :req-un [::name])) | |
(s/def ::items (s/coll-of pos-int?)) | |
(s/def ::active boolean?) | |
;; knowledge specific to this test data |
This file contains 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 foo) | |
(defn hello [x] (str "Hi " x)) | |
(ns bar) | |
(println (foo/hello "there")) | |
(remove-ns 'foo) | |
(println (resolve 'foo/hello)) |
This file contains 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
(require | |
'[clojure.main :as main] | |
'[clojure.pprint :as pp]) | |
(def strings | |
"Some strings that should fail somewhere in read/compile" | |
[":::5" | |
"(let [x])" | |
"(cond 1)" | |
"defmulti 5 class)" |
This file contains 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
;; Datomic sample code | |
;; schema query for attribute types in specified namespaces | |
(q '[:find ?attr | |
:in $ [?include-ns ...] ;; bind ?include-ns once for each item in collection | |
:where | |
[?e :db/valueType] ;; all schema types (must have a valueType) | |
[?e :db/ident ?attr] ;; schema type name | |
[(datomic.Util/namespace ?attr) ?ns] ;; namespace of name | |
[(= ?ns ?include-ns)]] ;; must match one of the ?include-ns |
This file contains 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
;; from leiningen, use [dorothy/dorothy "0.0.3"] | |
(require '[dorothy.core :as dot]) | |
;; dataflow copied from chat | |
;; https://github.com/pedestal/samples/blob/master/chat/chat-client/app/src/chat_client/behavior.clj | |
(def dataflow '{:transform | |
{:outbound {:init {} :fn outbound-transform} | |
:inbound {:init {} :fn inbound-transform} | |
:nickname {:init nil :fn nickname-transform}} | |
:effect {:outbound send-message-to-server} |
This file contains 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
(->> [(cycle [:fizz :_ :_]) | |
(cycle [:buzz :_ :_ :_ :_])] | |
(apply map vector) | |
(take 25)) |
This file contains 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
(comment "interop runtime exception repl-caught") | |
(/ 1 0) | |
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:163) | |
(comment "interop runtime exception pst") | |
(pst) | |
ArithmeticException Divide by zero | |
clojure.lang.Numbers.divide (Numbers.java:163) | |
clojure.lang.Numbers.divide (Numbers.java:3833) | |
;; elided |