Skip to content

Instantly share code, notes, and snippets.

Hello world.
(defn pivot
([data kf vf](pivot data kf vf +))
([data kf vf reduct-fn]
(apply merge-with reduct-fn
(map #(apply hash-map ((proj kf vf) %))
data))))
(defn chain-comp
"This takes a list of comparator functions, and chains them together.
It returns another comparator. It behaves similar to comp, in that
comparisons are done right to left."
[& comps]
(fn [a b]
(loop [remaining-comps (reverse comps)]
(let [iter-comp (first remaining-comps)
iter-result (iter-comp a b)]
(if (and (zero? iter-result) (next remaining-comps))
(defn apply-map
"This works like apply, gmabut for keyword arguments in a map."
[f & args]
(let [pos-args (butlast args)
a-map (last args)
applied-args (concat
(if pos-args pos-args [])
(cond
(nil? a-map) []
(map? a-map) (reduce concat a-map)
(defn str-drop-while
[pred coll]
(apply str (drop-while pred coll)))
(defn str-take-while
[pred coll]
(apply str (take-while pred coll)))
;These tests are how Sean Devlin proposes that this function should behave.
(deftest test-flatten-proposed
(are [expected nested-val] (= (flatten nested-val) expected)
;simple literals
nil nil
1 1
'foo 'foo
:keyword :keyword
1/2 1/2
#"[\r\n]" #"[\r\n]"
(defn vreplace
([s p r] (replace s p r))
([s p r & more]
(let [pair (take 2 more)
next-p (first pair)
next-r (second pair)
remaining (drop 2 more)]
(if next-r
(replace (replace s next-p next-r remaining) p r)
(replace s p r)))))
import java.util.regex.*;
import clojure.lang.Ifn;
/**Delagates the appropraite methods to the Pattern Object
However, it adds IFn ability as well.
*/
public class ClojurePattern implements IFn, Serializable{
public static ClojurePattern compile(String regex){
return new ClojurePattern(regex,0);
(def & comp)
(def p partial)
(defn- sym->key [x] (keyword (str x)))
(defn- sym-rep [x s-map]
(let [k (sym->key x)]
(if (contains? s-map k)
(s-map k)
x)))
(ns crr.launch-once
(:require
[clojure.contrib [duck-streams :as duck]])
(:use
lib.sfd.swing.messages
lib.sfd.thread-utils
))
;(def my-agent (agent 0))