diff --git a/README.md b/README.md index a0448027..53b955e0 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The ExpenseReport example currently exists in the following languages: - [C](expensereport-c/) - [C#](expensereport-csharp/) - [C++](expensereport-cxx/) +- [Clojure](expensereport-clojure/) ⇐ This one was particularly painful to intentionally write poorly, I almost cried. - [Dart](expensereport-dart/) - [Go](expensereport-go/) - [Java](expensereport-java/) diff --git a/expensereport-clojure/.gitignore b/expensereport-clojure/.gitignore new file mode 100644 index 00000000..d956ab0a --- /dev/null +++ b/expensereport-clojure/.gitignore @@ -0,0 +1,13 @@ +/target +/classes +/checkouts +profiles.clj +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +/.prepl-port +.hgignore +.hg/ diff --git a/expensereport-clojure/Makefile b/expensereport-clojure/Makefile new file mode 100644 index 00000000..5ec8df1c --- /dev/null +++ b/expensereport-clojure/Makefile @@ -0,0 +1,14 @@ +.PHONY: all +all: test + +.PHONY: test +test: + lein test + +.PHONY: run +run: + lein run + +.PHONY: clean +clean:: + lein clean diff --git a/expensereport-clojure/README.md b/expensereport-clojure/README.md new file mode 100644 index 00000000..4e8aa749 --- /dev/null +++ b/expensereport-clojure/README.md @@ -0,0 +1,22 @@ +# expensereport-clojure + +A Clojure library designed to ... well, that part is up to you. + +## Usage + +FIXME + +## License + +Copyright © 2021 FIXME + +This program and the accompanying materials are made available under the +terms of the Eclipse Public License 2.0 which is available at +http://www.eclipse.org/legal/epl-2.0. + +This Source Code may also be made available under the following Secondary +Licenses when the conditions for such availability set forth in the Eclipse +Public License, v. 2.0 are satisfied: GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or (at your +option) any later version, with the GNU Classpath Exception which is available +at https://www.gnu.org/software/classpath/license.html. diff --git a/expensereport-clojure/project.clj b/expensereport-clojure/project.clj new file mode 100644 index 00000000..2e448aa4 --- /dev/null +++ b/expensereport-clojure/project.clj @@ -0,0 +1,5 @@ +(defproject expensereport-clojure "0.1.0-SNAPSHOT" + :description "Expense Report example in Clojure" + :dependencies [[org.clojure/clojure "1.10.1"]] + :main expensereport-clojure.core/main + :repl-options {:init-ns expensereport-clojure.core}) diff --git a/expensereport-clojure/src/expensereport_clojure/core.clj b/expensereport-clojure/src/expensereport_clojure/core.clj new file mode 100644 index 00000000..2fe112a2 --- /dev/null +++ b/expensereport-clojure/src/expensereport_clojure/core.clj @@ -0,0 +1,25 @@ +(ns expensereport-clojure.core) + +(defn expense [type amount] {:type type :amount amount}) + +(defn print-report + [expenses] + (def total (atom 0)) + (def meal-expenses (atom 0)) + (println "Expenses: " (.toString (java.util.Date.))) + (doall (for [expense (into #{} expenses)] (do + (if (or (= (:type expense) :breakfast) (= (:type expense) :dinner)) (reset! meal-expenses (+ @meal-expenses (:amount expense)))) + (def expense-name (case (:type expense) + :car-rental "Car Rental" + :breakfast "Breakfast" + :dinner "Dinner")) + (def mealOverExpensesMarker (if (or (and (= (:type expense) :breakfast) (>= (:amount expense) 1000)) (and (= (:type expense) :dinner) (>= (:amount expense) 5000))) "X" " ")) + (println expense-name "\t" (:amount expense) "\t" mealOverExpensesMarker) + (reset! total (+ @total (:amount expense)))))) + (println "Meal expenses: " @meal-expenses) + (println "Total expenses: " @total) +) + +(defn main [] + (print-report [(expense :car-rental 100) (expense :breakfast 1000) (expense :breakfast 1001) (expense :dinner 5000) (expense :dinner 5001)]) +) diff --git a/expensereport-clojure/test/expensereport_clojure/core_test.clj b/expensereport-clojure/test/expensereport_clojure/core_test.clj new file mode 100644 index 00000000..d822e5e6 --- /dev/null +++ b/expensereport-clojure/test/expensereport_clojure/core_test.clj @@ -0,0 +1,7 @@ +(ns expensereport-clojure.core-test + (:require [clojure.test :refer :all] + [expensereport-clojure.core :refer :all])) + +(deftest a-test + (testing "FIXME, I fail." + (is (= 1 1))))