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 partitions [sizes coll] | |
(lazy-seq | |
(when-let [n (first sizes)] | |
(when-let [s (seq coll)] | |
(cons (take n coll) | |
(partitions (next sizes) (drop n coll))))))) | |
(defn partitions [sizes coll] | |
(second (reduce | |
(fn [[coll res] n] |
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 map-all | |
"Sequence of results from applying f to the first of each of colls. | |
Empty colls are dropped and evaluation proceeds." | |
[f & colls] | |
(lazy-seq | |
(when-let [s (seq colls)] | |
(cons (apply f (map first colls)) | |
(apply map-all f (for [coll (map rest s) | |
:when (seq coll)] | |
coll)))))) |
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
(definterface AutomataOps | |
(^long bound [^long x]) | |
(^long getCell [^long x ^long y]) | |
(^long countNeighbors [^long x ^long y]) | |
(^long alive [^long cell ^long neighbors]) | |
(^long updateCell [^long x ^long y])) | |
(defprotocol Automata | |
(update [this])) |
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
F:\Clojure\Projects\myproject>lein deps | |
Copying 2 files to F:\Clojure\Projects\myproject\lib | |
Copying 2 files to F:\Clojure\Projects\myproject\lib\dev | |
F:\Clojure\Projects\myproject>lein swank | |
Var *classpath* not marked :dynamic true, setting to :dynamic. You should fix th | |
is before next release! | |
Exception in thread "main" java.lang.ClassNotFoundException: swank/clj_contrib/p | |
print$fn__648$pretty_pr_code_STAR___649, compiling:(swank/clj_contrib/pprint.clj |
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
(defproject myproject "1.0.0-SNAPSHOT" | |
:description "FIXME: write" | |
:dependencies [[org.clojure/clojure "1.3.0-alpha6"] | |
[org.clojure/clojure-contrib "1.2.0"]] | |
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]) |
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
;;https://github.com/naleksander/instrumentos/blob/master/src/instrumentos/yield.clj | |
(defn funnel [] | |
(let [q (java.util.concurrent.SynchronousQueue.)] | |
[(take-while (partial not= q) | |
(repeatedly #(.take q))) | |
(fn | |
([e] (.put q e)) | |
([] (.put q q)))])) |
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
(use '[clojure.contrib.lazy-seqs :only [primes]] | |
'[clojure.set]) | |
(def prime? | |
(let [mem (ref #{}) | |
primes (ref primes)] | |
(fn [n] | |
(if (< n (first @primes)) | |
(@mem n) | |
(let [[mems ps] (split-with #(<= % n) @primes)] |
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
; Turn a map into a JTree | |
; keys can be any object using toString to display | |
; listener is called as (listener seq-of-keys-to-selected-node) | |
;root | |
; |-child-1 | |
; | |-Child-1-1 | |
; | |-child-1-2 | |
; |-child-2 | |
; |-child-3 |
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.awt Toolkit] | |
[java.awt.datatransfer StringSelection DataFlavor | |
Transferable UnsupportedFlavorException]) | |
(defn clear-clipboard [] | |
(.. Toolkit | |
getDefaultToolkit | |
getSystemClipboard | |
(setContents | |
(proxy [Transferable] [] |
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
(use 'clojure.walk) | |
;from psykotic http://gist.github.com/328830 | |
(defmacro >> [& xs] | |
(reduce (fn [x1 x2] | |
(let [x1- (gensym)] | |
`(let [~x1- ~x1] | |
~(postwalk (fn [x] (if (= x '%) x1- x)) x2)))) | |
(macroexpand-all xs))) |
NewerOlder