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
;; Example use of unresolve: | |
;; user=> (unresolve #'replace) | |
;; (replace clojure.core/replace) | |
;; user=> (use 'clojure.string) | |
;; WARNING: replace already refers to: #'clojure.core/replace in namespace: user, being replaced by: #'clojure.string/replace | |
;; WARNING: reverse already refers to: #'clojure.core/reverse in namespace: user, being replaced by: #'clojure.string/reverse | |
;; nil | |
;; user=> (unresolve #'replace) | |
;; (replace clojure.string/replace) |
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
package perf; | |
import clojure.lang.AFunction; | |
import clojure.lang.IFn; | |
import clojure.lang.Indexed; | |
import clojure.lang.Numbers; | |
import clojure.lang.RT; | |
import clojure.lang.Var; | |
import java.awt.image.BufferedImage; | |
import perf.core.foo.fn__14; |
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
(ns piper.core | |
(:require [clojure.java.io :as io] | |
[clojure.string :as str]) | |
(:import (java.io Reader Writer BufferedReader))) | |
(defn str-seq-reader | |
"Return a java.io.Reader that returns the same sequence of | |
characters as are in the concatenation of the sequence of strings | |
given as an argument. Consumes only as much of the sequence as needed | |
for any given read operation." |
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
;; In a fresh Clojure 1.5.1 'lein repl' | |
;; clojure.edn is not loaded yet | |
user=> (clojure.edn/read-string "(5)") | |
ClassNotFoundException clojure.edn java.net.URLClassLoader$1.run (URLClassLoader.java:366) | |
;; trying to eval this form does not do it, because it fails to analyze as a whole | |
user=> (eval `(when true (require 'clojure.edn) (clojure.edn/read-string "(5)"))) |
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
;; Examples showing that when *print-meta* is bound to true, clojure.pprint/pprint appears | |
;; to show metadata on symbols, but not on collections. Can be misleading when only *some* | |
;; metadata is shown. Led me to believe the other metadata wasn't there until I double-checked | |
;; with pr. | |
(defn ppm [f m] | |
(binding [*print-meta* m] | |
(clojure.pprint/pprint f))) | |
(defn prm [f m] |
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
(ns inputstream.core | |
(:require [clojure.java.io :as io])) | |
(defn read-is [^java.io.InputStream is] | |
(let [bufsize 8192 | |
buf (byte-array bufsize)] | |
(loop [total-len 0] | |
(let [n (.read is buf)] | |
(cond |
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
;; TBD: What is going on here? | |
;; Why does (Math/abs (f2 -3)) cause a | |
;; reflection warning, but neither of the other variants does? | |
user=> (clojure-version) | |
"1.6.0" | |
user=> (set! *warn-on-reflection* true) | |
true | |
user=> (defn ^{:tag 'long} f1 [x] (inc x)) |
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=> (def b 7) | |
#'user/b | |
user=> (def fplus2 (reify java.lang.Object (hashCode [user/b] (+ user/b 2)))) | |
#'user/fplus2 | |
user=> (.hashCode fplus2) | |
9 |
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
;; Clojure JIRA ticket CLJ-865: http://dev.clojure.org/jira/browse/CLJ-865 | |
;; was created with the intent of changing some of the behavior below, but it is | |
;; not clear as of late 2014 whether the behavior is considered a bug that should | |
;; be changed. | |
;; Nicola Mometto pointed out that there may be similar issues with metadata | |
;; being eliminated for primInvoke's and functions defined with definline. | |
;; Perhaps http://dev.clojure.org/jira/browse/CLJ-1533 is related. | |
user=> *clojure-version* |
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
;; Example: | |
;; (merge-sorted-seqs < (range 10 1000 3) (range 12 1000 5)) | |
(defn merge-sorted-seqs [cmpf seq1 seq2] | |
(let [seq1wins (and (seq seq1) | |
(or (nil? (seq seq2)) | |
(cmpf (first seq1) (first seq2))))] | |
(if seq1wins | |
(lazy-seq (cons (first seq1) | |
(merge-sorted-seqs cmpf (next seq1) seq2))) |
OlderNewer