Skip to content

Instantly share code, notes, and snippets.

View lildata's full-sized avatar

Programming is fun lildata

View GitHub Profile
(pprint (loaded-libs))
user=> (System/getProperty "java.class.path")
"/some/path/clojure/clojure.jar"
user=> (System/setProperty "java.class.path" ".:/some/path/clojure/clojure.jar:/some/other/lib.jar")
".:/some/path/clojure/clojure.jar:/some/other/lib.jar"
user=> (def cl (-> (Thread/currentThread) (.getContextClassLoader)))
#'user/cl
user=> cl
#<DynamicClassLoader clojure.lang.DynamicClassLoader@19c5466b>
user=> (-> cl (.addURL (java.net.URL. "file:///some/other/lib.jar")))
nil
import java.util.Arrays;
import java.util.Iterator;
import clojure.lang.IFn;
import clojure.lang.LazySeq;
import clojure.lang.RT;
public class Main {
public static void main(String[] args) {
(ns learning.hello
  (:gen-class))

The :gen-class directive in the ns declaration tells Clojure to generate a named Java class when it compiles the namespace.

You can compile in the repl !!

user=&gt; (load "learning/hello")
(defnk net-present-value
"(net-present-value :rate 0.05 :cashflows [-1000 500 600 800])"
[:rate :cashflows]
(reduce + (map #(/ %1 (pow (inc rate) %2)) cashflows (range))))
@lildata
lildata / common-1-letter-var-names.clj
Last active September 10, 2015 21:08
One letter variables names that most people will probably recognize
x: item
n: a number
m: map
v: value
k: key
i: index
c: char
t: tree
f: function
@lildata
lildata / simple-date-format.clj
Created September 10, 2015 21:10
there is a simpler one I think if you have Java 8
(.format (java.text.SimpleDateFormat. "yyyy-MM-dd") (java.util.Date.))

\w is the same as [a-zA-Z0-9]

(dont cheat)