Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
(defmacro rec-lazy-seq | |
"Like lazy-seq, but also takes a single binding form that will be | |
a reference to the lazy seq object itself, so that the lazy seq can | |
be defined in terms of itself." | |
[[name] & body] | |
`(let [p# (promise) | |
ls# (lazy-seq | |
(let [~name (lazy-seq @p#)] | |
~@body))] | |
(deliver p# ls#) |
(require '[clojure.core.async :as a]) | |
(def xform (comp (map inc) | |
(filter even?) | |
(dedupe) | |
(flatmap range) | |
(partition-all 3) | |
(partition-by #(< (apply + %) 7)) | |
(flatmap flatten) | |
(random-sample 1.0) |
(ns reagent-test.core | |
(:require [reagent.core :as reagent :refer [atom]] | |
[datascript :as d] | |
[cljs-uuid-utils :as uuid])) | |
(enable-console-print!) | |
(defn bind | |
([conn q] | |
(bind conn q (atom nil))) |
N.B. This is now a library, thanks to the efforts of the wonderful @mtnygard. And the README does a good job of making clear just how terrible an idea it is to actually do this. :)
As any Clojurist knows, the REPL is an incredibly handy development tool. It can also be useful as a tool for debugging running programs. Of course, this raises the question of how to limit access to the REPL to authorized parties. With the Apache SSHD library, you can embed an SSH server in any JVM process. It takes only a little code to hook this up to a REPL, and to limit access either by public key or
(ns om-data.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true] | |
[datascript :as d])) | |
(enable-console-print!) | |
(def schema {}) | |
(def conn (d/create-conn schema)) | |
We can look at two sides of the management coin: What do the individuals get out of it? And what benefit does the whole system derive from it?
I will disregard any benefits that accrue to managers just by holding the position of managing. Those are just circular logic. Circular logic abounds in discussions of management and hierarchy. For example, consider status reports. It will be said that status reports are necessary so managers know what their employees are working on. It’s
;; Ref-based Santa Claus solution, Written by Mark Engelberg | |
;; (start-simulation) to run | |
(def *num-elves* 10) | |
(def *num-reindeer* 9) | |
;; Santa is a ref containing either {:state :asleep} or {:state :busy, :busy-with <sequence-of-workers>} | |
(def santa (ref {:state :asleep})) | |
(defn waiting-room [capacity] |
;; Datomic example code | |
(use '[datomic.api :only (db q) :as d]) | |
;; ?answer binds a scalar | |
(q '[:find ?answer :in ?answer] | |
42) | |
;; of course you can bind more than one of anything | |
(q '[:find ?last ?first :in ?last ?first] | |
"Doe" "John") |