Skip to content

Instantly share code, notes, and snippets.

(defna findo [x l o]
([_ [[y :- o] . _] _]
(project [x y] (== (= x y) true)))
([_ [_ . c] _] (findo x c o)))
(defn typedo [c x t]
(conda
[(lvaro x) (findo x c t)]
[(matche [c x t]
([_ [[y] :>> a] [s :> t]]
(defmacro simple-let
[bindings & body]
`((fn ~(->> (partition-all 2 bindings) (map first) (vec))
~@body)
~@(->> (partition-all 2 bindings) (map second))))
(simple-let [x true]
(= false x))
;; returns false, because x is bound to true
(defn unevaluated?
[expr]
(or (symbol? expr)
(and (seq? expr)
(not= (first expr) `quote))))
(defn literal?
[x]
(and (not (unevaluated? x))
(or (not (or (vector? x) (map? x)))
(deftest test-logic-119-disequality-1
(is (= (run* [q]
(!= {1 2 3 4} 'foo))
'(_0))))
@aamedina
aamedina / gist:7755360
Last active December 30, 2015 01:19
new multimethod template conventions
(def account-columns
"Columns for the account model. Will be used to specify
the content of the generated table header cells."
[{:name :select-all
:content "Select All"}]
(defmulti th
"Multimethod template function. Dispatches on the value specified.
If the value is a keyword and the first argument to the function when called is a map,
it looks up the value in the map for itself. E.g. given {:name :select-all}, calling
(run-dataflow {} {msg/type :inc msg/path [:counter]}) =>
{:old {}, :new {:counter 1}, :added #{[:counter]}, :removed #{}, :updated #{},\
:deltas [], :context {:message {:foundation.app.message/type :inc, :foundatio\
n.app.message/path [:counter]}}}
(defn xhr
[uri method content headers]
(let [c (chan)
m (mult c)]
(if-let [cached (get-cached uri)]
(let [tapped (tap m (chan))]
(put! tapped cached)
tapped)
(if-let [source (get @outstanding-requests uri)]
(tap source (chan))
(defn GET
"Sends a GET request to the specified URI."
[uri & {:keys [headers] :or {:headers {}}}]
(xhr uri "GET" nil (merge *headers* headers)))
(defn POST
"Sends a POST request to the specified URI with the given payload."
[uri & {:keys [body headers] :or {headers {} body nil}}]
(xhr uri "POST" body (merge *headers* headers)))
(defn dispatches
[dispatch]
(->> (iterate zip/next (zip/vector-zip dispatch))
(take-while (complement zip/end?))
(map zip/node)
(map #(replace {% :*} dispatch))))
;; the runtime is centered around three fundamental queues
;; 1) the input queue - your app sends messages to the input queue which uniquely identify a piece of state to update according
;; to the message params. These parameters are specified as part of the function definition, so there's no need to search around
;; for "configs" or "spec maps" anywhere in the code - app behavior is specified in the functions themselves.
;; 2) the output queue - this queue gets all messages that need to be processed outside of the application runtime -
;; common side effects that are relayed through this queue include DOM manipulation and Ajax requests
;; 3) the app model queue - this queue propagates renderable changes in the data model to the view (the actual frontend)
;; through the use of fine grained messages, called rendering deltas