Let's say you want to use cljs.js
to eval
code using functions declared in your project.
Expressions that only use core functions are simple to evaluate:
(ns foo.try-eval
(:require [cljs.js :as cljs]))
(def compiler-state (cljs/empty-state))
Let's say you want to use cljs.js
to eval
code using functions declared in your project.
Expressions that only use core functions are simple to evaluate:
(ns foo.try-eval
(:require [cljs.js :as cljs]))
(def compiler-state (cljs/empty-state))
(ns shades.lenses) | |
; We only need three fns that know the structure of a lens. | |
(defn lens [focus fmap] {:focus focus :fmap fmap}) | |
(defn view [x {:keys [focus]}] (focus x)) | |
(defn update [x {:keys [fmap]} f] (fmap f x)) | |
; The identity lens. | |
(defn fapply [f x] (f x)) | |
(def id (lens identity fapply)) |
(comment | |
This is the easiest and most concise way of calling an external process in Java. The inheritIO methods causes the command to output stdout and errout to the same place as your current process (which most of the times is the console), no need to create mechanisms for reading asynchronously from input streams to get at the information. | |
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html | |
) | |
(def ret (.waitFor (-> (ProcessBuilder. ["gzip" "-t" "g.txt.gz"]) .inheritIO .start))) | |
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ | |
(defprotocol ReversibleMap | |
(rmap [m])) | |
(defn- rdissoc [d r v] | |
(if-let [[_ k] (find r v)] (dissoc d k) d)) | |
(deftype Bimap [^clojure.lang.IPersistentMap direct reverse] | |
Object | |
(hashCode [x] |
(defn new-q [] (java.util.concurrent.LinkedBlockingDeque.)) | |
(defn offer! | |
"adds x to the back of queue q" | |
[q x] (.offer q x) q) | |
(defn take! | |
"takes from the front of queue q. if q is empty, block until something is offer!ed into it" | |
[q] (.take q)) |