(ns example.macros | |
(:require | |
[cljs.analyzer :as a] | |
[cljs.compiler :as c])) | |
(defmacro complies? | |
"True if x satisfies and implements all methods of a protocol. | |
Ex. |
(ns allgress.datascript.util | |
(:require [clojure.walk :refer [postwalk]])) | |
;;; Datomic pull API will return :db/idents as references, like {:my-enum-att {:db/ident :enum-value}}. | |
;;; This function replaces with the Datascript equivalent {:my-enum-att :enum-value}. Only works | |
;;; for true "enums", whose only attribute in the entity map is :db/ident. | |
defn replace-enum-refs [entity-map] | |
(postwalk | |
(fn [arg] | |
(if (and (coll? arg) (map? (second arg)) (= 1 (count (second arg))) (contains? (second arg) :db/ident)) |
(ns favila.datomic-util.restore-datoms | |
"A \"manual\" datomic database restore. | |
Writes raw datoms (stored in a stream written by d/datoms) to an empty database. | |
Useful for memory databases: you can write out all the datoms in it, then read | |
them into another database. (Note mem dbs have no log or retractions)." | |
(:require [datomic.api :as d] | |
[clojure.edn :as edn])) | |
(defrecord datom [e a v tx added?]) |
;; ## State Methods | |
(defmulti initial-state | |
"Multimethod that returns the initial state for the supplied | |
page." :name) | |
(s/defmethod initial-state :default [r :- Route s :- (s/maybe AppState)] {}) | |
(defmulti page-title | |
"Returns the current page title for the supplied route." :name) |
Hello!
This is a commentary and discussion from walking through what happens on startup in [https://github.com/circleci/frontend], looking at this SHA in December 2014: [https://github.com/circleci/frontend/commit/273558250040ce197e44e683d5528381f36c4eea].
The first part is a literal walkthrough, where I'm tracing my reading of how the code works. This is a way to check my understanding, since of course I don't have all of your context. And it's also a way to echo back to you how someone else might experience this code without that context. The second part is about asking questions, making suggestions, and exploring some paths for making it even more awesome. I also mixed in a few asides in the walkthrough part where I jump ahead a bit.
Doing this with colleagues has worked well for me as a way to do in-depth code reviews about more abstract design and architectural questions. The goal of the the first part is to clarify we're all looking at the same thing, which creates the space and shared understa
(comment ; Fun with transducers, v2 | |
;; Still haven't found a brief + approachable overview of Clojure 1.7's new | |
;; transducers in the particular way I would have preferred myself - so here goes: | |
;;;; Definitions | |
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as: | |
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation | |
;; (The `[]` arity is actually optional; it's only used when calling | |
;; `reduce` w/o an init-accumulator). |
(ns kleene) | |
;; | |
;; Inspired by "Regexes, Kleene Algebras and Real Ultimate Power" | |
;; http://plastic-idolatry.com/erik/oslo2014.pdf | |
;; | |
;; What do we want to do?... | |
;; | |
;; (def p1 (times (Var. "w") (Var. "o") (Var. "w")) | |
;; (matches? p1 "wow") ;; true |
(in-ns 'eclj.core) | |
(defprotocol Fn | |
:on-interface clojure.lang.Fn | |
"Marker interface indicating invokeables that are explictly functions") | |
(defprotocol IFn | |
:on-interface clojure.lang.IFn | |
(^{:on :invoke} -invoke | |
[this] |