Skip to content

Commit

Permalink
Merge pull request #223 from PEZ/babashka
Browse files Browse the repository at this point in the history
Babashka: Use separate code from Clojure
  • Loading branch information
bddicken authored Dec 18, 2024
2 parents e09389e + b0b4742 commit 3ce202b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fibonacci/bb/code.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(defn- fibonacci [n]
(case n
0 0
1 1
(+ (fibonacci (- n 1))
(fibonacci (- n 2)))))

(defn main [u]
(println (reduce + (map fibonacci (range u)))))

(main (-> *command-line-args* first parse-long))
1 change: 1 addition & 0 deletions hello-world/bb/code.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(println "Hello, World!")
13 changes: 13 additions & 0 deletions loops/bb/code.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(defn main [u]
(let [r (rand-int 10000) ; Get a random number 0 <= r < 10k
v' (vec (repeat 10000 0)) ; Vector of 10k elements initialized to 0
v (mapv (fn [initial-value]
(let [inner-sum (reduce (fn [sum j]
(+ sum (rem j u))) ; Simple sum
initial-value
(range 100000))] ; 100k inner loop iterations, per outer loop iteration
(+ inner-sum r))) ; Add a random value to each element in array
v')] ; 10k outer loop iterations
(println (nth v r)))) ; Print out a single element from the array

(main (-> *command-line-args* first parse-long)) ; Get an input number from the command line
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ run "Haskell" "" "./hs/code"
run "V" "" "./v/code"
run "Chez Scheme" "chez --program" "./chez/code.so"
run "Clojure" "java -cp clojure/classes:$(clojure -Spath)" "./clojure/code"
run "Babashka" "bb" "./bb/code.clj"
run "COBOL" "" "./cobol/main"
#run "MAWK" "mawk -f" "./awk/code.awk"
#run "Babashka" "bb -cp clojure -m" "./babashka/code"
Expand Down

0 comments on commit 3ce202b

Please sign in to comment.