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
{:Ra (fnk [day-of-year lat] (solar-rad-et day-of-year lat)) | |
:Rs (fnk [tmax tmin {kRs 0.16} Ra] (-> (- tmax tmin) Math/sqrt (* kRs Ra))) | |
:Rso (fnk [alt Ra] (-> (* 2e-5 alt) (+ 0.75) (* Ra))) | |
:Rns (fnk [{a 0.23} Rs] (-> (- 1 a) (* Rs))) | |
:tmaxK (fnk [tmax] (to-kelvin tmax)) | |
:tminK (fnk [tmin] (to-kelvin tmin)) | |
:ea (fnk [tmin] (sat-vapour-pressure tmin)) | |
:term1 (fnk [tmaxK tminK {s 4.903e-9}] | |
(-> (Math/pow tmaxK 4) (+ (Math/pow tminK 4)) (* s) (/ 2))) | |
:term2 (fnk [ea] (-> (Math/sqrt ea) (* -0.14) (+ 0.34))) |
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
(deftype FinalizeReporter [x] | |
Object | |
(finalize [this] (println "Finalizing" x)) | |
clojure.lang.IDeref | |
(deref [this] x)) | |
(defn leaker [n] | |
(with-open [_ (reify java.io.Closeable (close [this]))] | |
(let [s (map #(FinalizeReporter. %) (take 10 (iterate inc 0)))] | |
(when (> n -1) |
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
;; Copyright Jason Wolfe and Prismatic, 2013. | |
;; Licensed under the EPL, same license as Clojure | |
(use 'plumbing.core) | |
(require '[clojure.java.shell :as shell] | |
'[clojure.string :as str]) | |
(import '[java.util HashSet] '[java.io File]) | |
(defn double-quote [s] (str "\"" s "\"")) |
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 plumbing.graph-async | |
(:require | |
[plumbing.fnk.pfnk :as pfnk] | |
[plumbing.fnk.schema :as schema] | |
[plumbing.core :as plumbing] | |
[plumbing.graph :as graph])) | |
;; async function has ^:async metadata, callback required key. | |
;; TODO: redo with just promises/futures once they have callback options | |
;; TODO: make nicer way to specify async fnks? |
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
(defnk foo [x y [s 1]] | |
(+ x (* y s))) | |
(foo {:x 2 :y 3 :s 2}) | |
; ==> 8 | |
;; 's' defaults to 1 | |
(foo {:x 2 :y 3}) | |
; ==> 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
(defn observe-graph [g record-node-time!] | |
(into {} | |
(for [[k f] g] | |
[k | |
(with-meta | |
(fn [m] | |
(let [t0 (System/nanoTime) | |
v (f m) | |
t1 (System/nanoTime)] | |
(record-node-time! k (- t1 t0)) |
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
(def lazy-stats (graph/lazy-compile stats-graph)) | |
(:m (lazy-stats {:xs [1 2 3 6]})) | |
; ==> 3 | |
; WIN: :m2 and :v are not computed. | |
(def par-stats (graph/parallel-compile stats-graph)) | |
(:v (par-stats {:xs [1 2 3 6]})) |
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
;; Functionally identical to (defn stats ...) above | |
(def stats (graph/eager-compile stats-graph)) | |
(stats {:xs [1 2 3 6]}) | |
; ==> {:n 4 | |
; :m 3 | |
; :m2 12.5 | |
; :v 3.5) | |
;; Result is error checked |
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
(defnk foo [x y [s 1]] | |
(+ x (* y s))) | |
(foo {:x 2 :y 3 :s 2}) | |
;; ==> 8 | |
(foo {:x 2 :y 3}) | |
;; ==> 5 | |
(foo {:x 2}) |
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
(def stats-graph | |
{:n (fnk [xs] (count xs)) | |
:m (fnk [xs n] (/ (sum identity xs) n)) | |
:m2 (fnk [xs n] (/ (sum #(* % %) xs) n)) | |
:v (fnk [m m2] (- m2 (* m m)))}) |