Skip to content

Instantly share code, notes, and snippets.

@billrobertson42
billrobertson42 / builder.clj
Created October 5, 2012 18:28
Turn a StringBuilder into a Clojure Function Take 2
(defn builder
([^StringBuilder sb]
(fn
([] (.toString sb))
([& args]
(doseq [arg args]
(.append sb arg)))))
([] (builder (StringBuilder.))))
(comment
@billrobertson42
billrobertson42 / autostub.clj
Created September 17, 2012 04:19
Auto create stub functions for Java when aot compiling Clojure. This is used to build Warscore (http://www.warscore.net)
(ns autostub
(require [clojure.string :as string]))
(set! *compile-path* "build/classes")
(defn export? [[var-symbol var-value]]
(and (fn? (var-get var-value)) ;; functions only
(not (.contains (str var-symbol) "->")))) ;; ignore record auto generated functions
(defn stub-fun-name [name]
@billrobertson42
billrobertson42 / gist:1721478
Created February 2, 2012 04:27
Turn a StringBuilder into Clojure function
user=> (def buffer (StringBuilder.))
#'user/buffer
user=>
(defn appender [^StringBuilder buffer]
(fn [& args]
(when-let [arg (first args)]
(.append buffer arg)
(recur (rest args)))))
user=> #'user/appender
user=>