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
(defmacro case-expr | |
"Like case, but only supports individual test expressions, which are | |
evaluated at macro-expansion time." | |
[e & clauses] | |
`(case ~e | |
~@(concat | |
(mapcat (fn [[test result]] | |
[(eval `(let [test# ~test] test#)) result]) | |
(partition 2 clauses)) | |
(when (odd? (count clauses)) |
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 nbody | |
(:gen-class)) | |
;; | |
;; Convenience aliases for unchecked arithmetic operations | |
(defmacro uc+ [& args] `(unchecked-add ~@args)) | |
(defmacro uc- [& args] `(unchecked-subtract ~@args)) | |
(defmacro uc* [& args] `(unchecked-multiply ~@args)) |
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 my-check [x] | |
(is (good? x)) | |
(defn another-check [x] | |
(is (alright? x)) | |
(def all-checks | |
[my-check another-check]) | |
(defn run-checks [browser] |
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
(#(let | |
[s (fn ! | |
([a] a) | |
([a & more] (for [x a y (apply ! more) :while (>= x y) :when (= x y)] x)))] | |
(first (apply s %&))) [1 2 100] [3 5 100] (range)) |
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
package com.damballa.cascading; | |
import java.io.IOException; | |
import cascading.scheme.Scheme; | |
import cascading.tap.Tap; | |
import cascading.tap.SinkTap; | |
import cascading.tuple.Fields; | |
import cascading.tuple.Tuple; | |
import cascading.tuple.TupleEntry; | |
import cascading.tuple.TupleEntryCollector; |
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 compile-and-dot | |
"Debugging helper. Compile a flow, print the steps, and write out the DOT | |
files for the flow operations and MR job steps." | |
[& args] | |
(let [^Flow flow (apply c/compile-flow args), name (.getName flow), | |
flow-path (str name "-flow.dot"), steps-path (str name "-steps.dot")] | |
(returning nil | |
(doseq [step (.getSteps flow)] | |
(prn step)) | |
(doto flow |
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
from sys import argv | |
from os.path import exists | |
script, from_file, to_file = argv | |
action = open(from_file) |
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
(import '(java.io ByteArrayInputStream ByteArrayOutputStream | |
ObjectInputStream ObjectOutputStream)) | |
(defmacro wtf | |
[] | |
(Boolean. false)) ;; note the lack of syntax-quote | |
--------- | |
user=> (wtf) |
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 example.locks | |
(:import [clojure.lang IDeref IBlockingDeref] | |
[java.util.concurrent TimeUnit] | |
[java.util.concurrent.locks Lock ReadWriteLock | |
ReentrantReadWriteLock])) | |
(defmacro ^:private with-lock | |
([lock body] | |
`(try (.lock ~lock) ~@body (finally (.unlock ~lock)))) | |
([lock timeout-ms timeout-val body] |
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
(let [a (agent nil), q (ref []), x (ref 0)] | |
(defn run-side-effects [_] | |
(let [fs (dosync | |
(let [q' @q] | |
(ref-set q []) | |
q'))] | |
(doseq [f fs] (f)))) | |
(defn alter-and-order-side-effects [] | |
(dosync |
OlderNewer