java version restriction has been lifted
This commit is contained in:
parent
9287dec83a
commit
ade2cff99d
|
@ -1,3 +1,23 @@
|
||||||
|
(def reduce
|
||||||
|
(fn (f xs initial-value)
|
||||||
|
(cond
|
||||||
|
((first xs) (reduce f (rest xs) (f initial-value (first xs))))
|
||||||
|
(true initial-value))))
|
||||||
|
|
||||||
|
(def map
|
||||||
|
(fn (f xs)
|
||||||
|
(reduce (fn (acc x) (cons acc (f x))) xs (list))))
|
||||||
|
|
||||||
|
(def range-list
|
||||||
|
(fn (x y init)
|
||||||
|
(if (< y x)
|
||||||
|
(do
|
||||||
|
(conj (range-list x (+ y 1) init) y))
|
||||||
|
init)))
|
||||||
|
(def range
|
||||||
|
(fn (x)
|
||||||
|
(range-list x 0 (list))))
|
||||||
|
|
||||||
(def fib
|
(def fib
|
||||||
(fn (n)
|
(fn (n)
|
||||||
(if (< n 2)
|
(if (< n 2)
|
||||||
|
@ -5,4 +25,20 @@
|
||||||
(+ (fib (- n 1))
|
(+ (fib (- n 1))
|
||||||
(fib (- n 2))))))
|
(fib (- n 2))))))
|
||||||
|
|
||||||
(println (fib 10))
|
|
||||||
|
(def benchmark-fn
|
||||||
|
(fn (x)
|
||||||
|
(let ((start (now)))
|
||||||
|
(fib x)
|
||||||
|
(- (now) start))))
|
||||||
|
|
||||||
|
|
||||||
|
(def run-benchmark
|
||||||
|
(fn (times)
|
||||||
|
(map (fn (x)
|
||||||
|
(println "Benchmark: " x)
|
||||||
|
(println "Took: " (benchmark-fn 30)))
|
||||||
|
(range times))))
|
||||||
|
|
||||||
|
|
||||||
|
(run-benchmark 20)
|
||||||
|
|
|
@ -50,13 +50,7 @@ public class Main {
|
||||||
"to redistribute it under certain conditions; \n" +
|
"to redistribute it under certain conditions; \n" +
|
||||||
"for details take a look at the LICENSE file.\n";
|
"for details take a look at the LICENSE file.\n";
|
||||||
|
|
||||||
private static void isJava8() throws RuntimeException {
|
|
||||||
if (System.getProperty("java.vm.specification.version").equals("1.8"))
|
|
||||||
throw new RuntimeException("Minimume required version of JDK is 1.8");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, RuntimeException {
|
public static void main(String[] args) throws IOException, RuntimeException {
|
||||||
Main.isJava8();
|
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
startRepl();
|
startRepl();
|
||||||
|
@ -75,7 +69,6 @@ public class Main {
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
String inputData = console.readLine("serene-> ");
|
String inputData = console.readLine("serene-> ");
|
||||||
//String inputData = "(fn (x) x)";
|
|
||||||
|
|
||||||
if (inputData == null) break;
|
if (inputData == null) break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue