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.lang.Throwable | |
(printStackTrace [this]) | |
(printStackTrace [this G__3890]) | |
(printStackTrace [this G__3891]) | |
(fillInStackTrace [this]) | |
(getCause [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
package main | |
func main() { | |
var( a = [...]int {81,32,45} | |
chin = make(chan int) | |
) | |
f1:=func() { | |
for d:=range chin { | |
println("d : %d" ,d); |
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
package main | |
func main() { | |
var( a = [...]int {81,32,45} | |
chin = make(chan int) | |
chout = make(chan int) | |
) | |
f1:=func() { | |
for d:=range chout { |
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 defmutabletype [type-name members] | |
(let [proto-name (symbol (str "I" (name type-name))) | |
member-setter-names (map #(symbol (str (name %) "!")) members) | |
member-setter-prototypes (map (fn [setter-name] `(~setter-name [this# newval#])) member-setter-names) | |
member-setter-fns (map (fn [setter-name member-name] `(~setter-name [this# newval#] (set! ~member-name newval#))) member-setter-names members) | |
member-getter-prototypes (map (fn [member-name] `(~member-name [this#])) members) | |
member-getter-fns (map (fn [member-name] `(~member-name [this#] ~member-name)) members) | |
annotated-members (vec (map (fn [name] (with-meta name (assoc (meta name) :volatile-mutable true))) members))] | |
`(do | |
(defprotocol ~proto-name |
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 IPoint | |
(getX []) | |
(setX [v])) | |
(deftype Point [^{:volatile-mutable true} x] | |
IPoint | |
(getX [this] x) | |
(setX [this v] (set! (.x this) v))) | |
(def sss (Point. 10)) |
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 display-local-bindings [] | |
(let [generate-code-to-print-symbol (fn [x] | |
`(pprint ['~x ~x])) | |
all-local-symbols (keys &env) | |
list-of-all-print-statements (map generate-code-to-print-symbol all-local-symbols)] | |
list-of-all-print-statements)) |
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 adapt-double | |
"Adds a class or type to the set of types accepted by the | |
2-argument-dispatch function sym." | |
[sym type-or-class] | |
(let [general-protocol (symbol (str sym "-double-protocol")) | |
function-name (symbol (str sym "-for-" (name type-or-class)))] | |
`(do (defprotocol ~(symbol (str (name sym) "-double-protocol-for-" | |
(name type-or-class))) | |
(~function-name [~'x ~'y])) | |
(extend ~type-or-class ~general-protocol |
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
(ns isomorphism.complex | |
(:refer-clojure) | |
(:require [clojure.core :as c] | |
[clojure.contrib.math :as m])) | |
(defrecord complex [re im]) | |
(defn dispatch-fn | |
([x y & ys] [(class x) (class y)])) | |
(defmulti c+ dispatch-fn) |
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 defmulti-m [multi-fn-name dispatch-fn ] | |
`(let [dfn# ~dispatch-fn | |
dvalmap# (atom {})] | |
(defn ~(symbol (str "add-method-to-" (name multi-fn-name))) | |
[key# method-fn#] | |
(swap! dvalmap# assoc key# method-fn#)) | |
(defn ~multi-fn-name [& args#] | |
(let [ks# (keys @dvalmap#) | |
k# (or (some #(when (dfn# % args#) %) ks#) :default) | |
func-to-call# (@dvalmap# k#)] |
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
nil | |
user> (defmulti hello even?) | |
#'user/hello | |
user> (defmethod hello false [n] | |
(println [:odd n]) | |
(recur (dec n))) | |
#<MultiFn clojure.lang.MultiFn@1e7c47> |