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
;;; Written when pondering | |
;;; http://stackoverflow.com/questions/9086926/create-a-proxy-for-an-specific-instance-of-an-object-in-clojure | |
(defmacro delegating-proxy [o class-and-ifaces ctor-args & impls] | |
(let [oname (gensym)] | |
(letfn [(delegating-impls [^java.lang.reflect.Method ms] | |
(let [mname (symbol (.getName ^java.lang.reflect.Method (first ms))) | |
arity-groups (partition-by #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms) | |
max-arity (max-key #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)] | |
`(~mname |
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
;;; See | |
;;; http://stackoverflow.com/questions/7240947/is-a-transparent-macrolet-possible | |
;;; for a discussion. | |
;;; Also see | |
;;; https://gist.github.com/1185513 | |
;;; for an earlier approach. | |
;;; src/deftest-magic/core.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
;;; See | |
;;; http://stackoverflow.com/questions/7240947/is-a-transparent-macrolet-possible | |
;;; for a discussion. | |
;;; src/deftest_magic/core.clj | |
(ns deftest-magic.core | |
(:use [clojure.tools.macro :only [macrolet]])) | |
(comment |
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
;;; See the inspirational SO question: http://stackoverflow.com/questions/3346382 | |
(require 'clojure.contrib.trace) | |
(defn trace-ns | |
"Replaces each function from the given namespace with a version wrapped | |
in a tracing call. Can be undone with untrace-ns. ns should be a namespace | |
object or a symbol." | |
[ns] | |
(doseq [s (keys (ns-interns ns)) |
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
(defmacro letrec [bindings & body] | |
(let [bcnt (quot (count bindings) 2) | |
arrs (gensym "bindings_array") | |
arrv `(make-array Object ~bcnt) | |
bprs (partition 2 bindings) | |
bssl (map first bprs) | |
bsss (set bssl) | |
bexs (map second bprs) | |
arrm (zipmap bssl (range bcnt)) | |
btes (map #(walk/prewalk (fn [f] |
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 unuse [ns] | |
(doseq [[n v] (ns-refers *ns*)] | |
(if (= (.. v ns name) ns) | |
(ns-unmap *ns* n)))) | |
(defn reuse [ns] | |
(unuse ns) | |
(remove-ns ns) | |
(use :reload-all ns)) |
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
(comment | |
(:b (DefaultMap. :foo {:a 1})) | |
; => :foo | |
(:a (DefaultMap. :foo {:a 1})) | |
; => 1 | |
(merge-with conj (DefaultMap. [] {}) {:a 1} {:a 2} {:a 3}) | |
; => {:a [1 2 3]} | |
) | |
;;; method implementations basically taken from clojure.core/emit-defrecord |
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 intern-alias | |
"Interns a Var called alias-sym in the namespace given by ns-or-sym | |
(which may be a symbol or an actual namespace object; defaults to | |
the current namespace). The binding of the new Var will be that of | |
the Var specified as var-or-sym; also, all metadata is copied from | |
the original to the alias. The original may be specified as either | |
a Var or a symbol." | |
([alias-sym var-or-sym] | |
(intern-alias *ns* alias-sym var-or-sym)) | |
([ns-or-sym alias-sym var-or-sym] |
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
java -cp "d:/xPrograms/leiningen/1.2.0/leiningen-1.2.0-RC2-standalone.jar;src;classes" leiningen.core uberjar | |
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: defproject in this context (project.clj:1) | |
at clojure.lang.Compiler.analyze(Compiler.java:5200) | |
at clojure.lang.Compiler.analyze(Compiler.java:5146) | |
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3031) | |
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5366) | |
at clojure.lang.Compiler.analyze(Compiler.java:5185) | |
at clojure.lang.Compiler.analyze(Compiler.java:5146) | |
at clojure.lang.Compiler.eval(Compiler.java:5423) | |
at clojure.lang.Compiler.load(Compiler.java:5852) |