This file contains 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
user> (defn fast-max [k x & more] | |
(first | |
(reduce (fn [[x x-key :as orig] y] | |
(let [[_ y-key :as new] [y (k y)]] | |
(if (> x-key y-key) | |
orig | |
new))) | |
[x (k x)] | |
more))) | |
This file contains 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
user> (defn ask-mathematica [var-name] | |
`(* ~var-name 10)) | |
#'user/ask-mathematica | |
user> (defmacro solve-pde [var1 var2] | |
`(+ ~var2 ~(ask-mathematica var1))) | |
#'user/solve-pde | |
user> (let [x 1 y 5] (solve-pde x y)) | |
15 |
This file contains 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 getopt-map | |
"Turn an option seq into a map of keyword=>[values] pairs. If | |
=> (getopt-map (getopt-seq nil \"ab:c::d\" (into-array String [\"-ab\" \"10\"]))) | |
{:b [\"10\"], :a [nil]} | |
=> (getopt-map (getopt-seq nil \"ab:c::d\" (into-array String [\"-ab\" \"10\" \"-b\" \"1\"]))) | |
{:b [\"10\" \"1\"], :a [nil]}" | |
[[opt-seq non-opts]] | |
(assoc | |
(reduce |
This file contains 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
;; This is how namespaces are serialized to a string | |
clojail.core> (print-dup *ns* *out*) | |
#=(find-ns clojail.core)nil | |
;; This is how they're printed normally | |
clojail.core> (eval `(println ~*ns*)) | |
#<Namespace clojail.core> | |
nil | |
;; Sensibly, you can't deserialize a namespace when read-eval is false |
This file contains 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
user=> (set! *warn-on-reflection* true) | |
true | |
user=> (defrecord A [^int x]) | |
user.A | |
user=> (defrecord B [^A a]) | |
user.B | |
user=> (. (A. 1) x) | |
1 | |
user=> (.. (B. (A. 1)) a x) | |
Reflection warning, NO_SOURCE_PATH:44 - reference to field x can't be resolved. |
This file contains 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
C:\Documents and Settings\Alan\My Documents\Programming\clojure\clojail>cake help | |
The system cannot find the path specified. | |
Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll'. | |
C:/Ruby187/lib/ruby/gems/1.8/gems/cake-0.6.0/bin/cake:464:in `sleep': Interrupt | |
from C:/Ruby187/lib/ruby/gems/1.8/gems/cake-0.6.0/bin/cake:464:in `with_ | |
socket' | |
from C:/Ruby187/lib/ruby/gems/1.8/gems/cake-0.6.0/bin/cake:426:in `send_ | |
command' | |
from C:/Ruby187/lib/ruby/gems/1.8/gems/cake-0.6.0/bin/cake:718 | |
from C:/Ruby187/bin/cake:19:in `load' |
This file contains 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
(cond ; can be hard to tell which is a test and which is a return value | |
(zero? (reduce + input-values)) 0 | |
(empty? (filter #{val1 val2 val3} (map #(foo x (nth % 4)) | |
y))) | |
(some #{question answer} (last user-input)) | |
...) | |
(cond ; looks weird, and leaves a complex last-form in doubt anyway | |
(zero? (reduce + input-values)) | |
0 |
This file contains 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
gettimeofday({1296499016, 975065}, NULL) = 0 | |
gettimeofday({1296499016, 975102}, NULL) = 0 | |
gettimeofday({1296499016, 975128}, NULL) = 0 | |
rt_sigprocmask(SIG_BLOCK, [IO], [HUP TERM IO], 8) = 0 | |
ioctl(3, FIONREAD, [0]) = -1 EIO (Input/output error) | |
kill(1793, SIGHUP) = 0 | |
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfc0fba8) = -1 EIO (Input/output error) | |
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfc0fb14) = -1 EIO (Input/output error) | |
ioctl(3, SNDCTL_TMR_STOP or TCSETSW, {B0 -opost -isig -icanon -echo ...}) = -1 EIO (Input/output error) | |
write(3, "\7", 1) = -1 EIO (Input/output error) |
This file contains 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 take-randnth [num coll] | |
(take num | |
(rest | |
(map first | |
(iterate (fn [[ret items]] | |
(let [idx (rand-int (count items))] | |
[(items idx) | |
(subvec (assoc items idx (items 0)) | |
1)])) | |
[nil |
This file contains 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 unfold | |
"Next and done? are functions that operate on a seed. next should | |
return a pair, [value new-seed]; the value half of the pair is | |
inserted into the resulting list, while the new-seed is used to | |
continue unfolding. Notably, the value is never passed as an | |
argument to either next or done?." | |
[next done? seed] | |
((fn unfold* | |
[seed] | |
(lazy-seq |