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
(set! *warn-on-reflection* true) | |
(defn apply-fn1 [x f arg] | |
;; apply f | |
x) | |
(defmacro apply-fn2 [x f arg type] | |
(vary-meta (do | |
;; apply f | |
x) |
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
(require '[clojure.spec :as s]) | |
(derive ::x ::x-or-y) | |
(derive ::y ::x-or-y) | |
(defmulti multifn first) | |
(defmethod multifn ::x-or-y [_] | |
(s/tuple keyword? number?)) |
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 foo | |
(:require [clojure.spec :as s] | |
[clojure.walk :as walk])) | |
(defn- ->sym | |
"Returns a symbol from a symbol or var" | |
[x] | |
(if (var? x) | |
(let [^clojure.lang.Var v x] | |
(symbol (str (.name (.ns v))) |
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 acl2s.core | |
(:require [clojure.walk :as walk])) | |
(def replacements | |
{'nat `(fn [x#] (and (integer? x#) (<= 0 x#))) | |
'plus `+ | |
'minus `-}) | |
(defn replace-symbols* [expr] | |
(if-not (list? expr) |
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
(require '[clojure.spec :as s]) | |
(s/def ::a any?) | |
(s/def ::x (s/keys :opt-un [::a])) | |
(let [x (loop [i 0 | |
x {:a 10}] | |
(if (== i 10000) | |
x |
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 evaluated [syms & body] | |
(let [m (into {} (map (juxt identity gensym) syms))] | |
`(let [~@(mapcat (fn [temp-sym] [temp-sym `(gensym)]) (vals m))] | |
`(let [~~@(mapcat reverse m)] | |
~(let [~@(mapcat identity m)] | |
~@body))))) | |
(defmacro foo [a b] | |
`(+ ~a ~a ~b ~b)) |
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 foo.bar | |
(:require [criterium.core :as c]) | |
(:import [clojure.lang Indexed Counted])) | |
(defmacro c! [& form] | |
`(c/with-progress-reporting (c/quick-bench (do ~@form)))) | |
(defn fn1 [u] | |
(dotimes [i (.count ^Counted u)] | |
(.nth ^Indexed u (unchecked-int i)))) |
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 !integer [buffer offset size le? value] | |
`(doto ~buffer | |
~@(map (fn [i] | |
`(aset ~(+ offset (if le? i (- size i 1))) | |
(unchecked-byte | |
(bit-and (unsigned-bit-shift-right ~value ~(* 8 i)) | |
0xFF)))) | |
(range size)))) | |
(defmacro ?integer [buffer offset size le?] |
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
(require '[criterium.core :as c]) | |
(set! *warn-on-reflection* true) | |
(set! *unchecked-math* :warn-on-boxed) | |
(defn repeatedly! | |
([^long n f] | |
(loop [i 0 | |
v (transient [])] | |
(if (== i n) |
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 test | |
"Performance comparison between defprotocol and definterface | |
with primitive args and return values." | |
(:require [criterium.core :as c])) | |
(set! *warn-on-reflection* true) | |
(set! *unchecked-math* :warn-on-boxed) | |
(defn no-meta | |
{:inline (fn [arg] `(with-meta ~arg nil))} |