Skip to content

Instantly share code, notes, and snippets.

View nforgerit's full-sized avatar

Nicolas Forgerit nforgerit

View GitHub Profile
@nforgerit
nforgerit / infix-calc.clj
Created November 24, 2017 09:59
Clojure: Infix Calculator
(defn tokenize [expr]
(let [to-chars #(clojure.string/split (clojure.string/replace % " " "") #"")
is-digit? #(and % (re-find #"^\d+$" %))]
(reverse
(reduce
(fn [[t & ts :as tokens] token]
(if (and (is-digit? token) (is-digit? t))
(cons (str t token) ts)
(cons token tokens)))
'(), (to-chars expr)))))
@nforgerit
nforgerit / dynamic-fn-symbol.clj
Created November 23, 2017 00:03
Clojure: Dynamic fn symbol
(defn uuid [] (str (java.util.UUID/randomUUID)))
;; => #'user/uuid
(defmacro rule [body]
(eval `(def ~(symbol (str "rule--" (uuid) "--1"))
(fn [] ~body))))
;; => #'user/rule
(rule (println "hej"))
;; => #'user/rule--a43302b7-a7f3-4648-9a07-0d37554f4ac8--1