Skip to content

Instantly share code, notes, and snippets.

(ns java2dot.core)
(def srcpath "/Users/paul/src/clojure/src/jvm/clojure/lang/")
(defn system [cmd writedata]
(let [proc (.. java.lang.Runtime (getRuntime) (exec (into-array cmd)))
isr (new java.io.InputStreamReader
(. proc (getInputStream)) "ISO-8859-1")
osr (new java.io.OutputStreamWriter (. proc (getOutputStream)))
baos (new java.io.ByteArrayOutputStream)]
@pjstadig
pjstadig / freqs.clj
Created February 14, 2014 11:20
The frequencies of characters from a large Clojure project (~23k lines of code; ~21k lines of test code).
(require 'clojure.pprint)
(require '[clojure.java.io :as io])
(with-open [m (io/writer "/tmp/freqs.txt")] (clojure.pprint/pprint (reverse (sort-by val (frequencies (mapcat seq (mapcat (fn [x] (with-open [x (io/reader x)] (doall (line-seq x)))) (filter (fn [f] (.endsWith (.getPath f) ".clj")) (concat (file-seq (io/file "src")) (file-seq (io/file "test"))))))))) m))
paul@samson:~$ clojure
Clojure 1.6.0
user=> (reduce + [])
0
user=> (reduce + [nil])
nil
user=> (reduce + [nil 1])
NullPointerException clojure.lang.Numbers.ops (Numbers.java:961)

mcfalc[5:31 PM] actually, last night i put together a visual clojure.zip/zipper application so you can see how zippers work interactively.

mcfalc[5:31 PM]but it's funny because i can convert it to a zork representation too.

mcfalc[5:32 PM]You are on a branch. To the left is a clojure.lang.PersistentVector. To the south there is a Number...

user=> (use 'criterium.core)
nil
user=> (bench (dorun (apply concat (repeat 1000000 '(1)))))
WARNING: Final GC required 2.040460552606568 % of runtime
Evaluation count : 180 in 60 samples of 3 calls.
Execution time mean : 391.129558 ms
Execution time std-deviation : 4.197992 ms
Execution time lower quantile : 384.915568 ms ( 2.5%)
Execution time upper quantile : 399.707688 ms (97.5%)
Overhead used : 3.750073 ns
paul@mbp:~$ clojure
Clojure 1.6.0
user=> (defrecord Foo [foo bar])
user.Foo
user=> (Foo. "foo" "bar")
#user.Foo{:foo "foo", :bar "bar"}
user=> (assoc (Foo. "foo" "bar") :baz "baz")
#user.Foo{:foo "foo", :bar "bar", :baz "baz"}
user=> (dissoc (assoc (Foo. "foo" "bar") :baz "baz") :foo)
{:bar "bar", :baz "baz"}
paul@samson:~$ clojure
Clojure 1.7.0-alpha2
user=> (format "this is an integer: %d" 1N)
IllegalFormatConversionException d != clojure.lang.BigInt java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:4045)
user=> (format "this is an integer: %d" (biginteger 1N))
"this is an integer: 1"
user=>
Clojure 1.6.0
user=> (str (map println (range 1 5)))
1
2
3
4
"clojure.lang.LazySeq@e1781"
user=>
Clojure 1.6.0
user=> (long 9/4)
2
user=> (partition-all (long 9/4) (range 10))
((0 1) (2 3) (4 5) (6 7) (8 9))
user=> (partition-all 9/4 (range 10))
((0 1 2) (3 4 5) (6 7 8) (9))
public final class reducers.core$foo extends clojure.lang.AFunction {
public static final clojure.lang.Keyword const__0;
public static final clojure.lang.Keyword const__1;
public static final clojure.lang.AFn const__2;
public static {};
Code:
0: aconst_null