Skip to content

Commit

Permalink
Add version in Clojure.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhujer committed Sep 13, 2021
1 parent 2e48327 commit ddeff1a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
13 changes: 13 additions & 0 deletions expensereport-clojure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
/.prepl-port
.hgignore
.hg/
14 changes: 14 additions & 0 deletions expensereport-clojure/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: all
all: test

.PHONY: test
test:
lein test

.PHONY: run
run:
lein run

.PHONY: clean
clean::
lein clean
22 changes: 22 additions & 0 deletions expensereport-clojure/README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions expensereport-clojure/project.clj
Original file line number Diff line number Diff line change
@@ -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})
25 changes: 25 additions & 0 deletions expensereport-clojure/src/expensereport_clojure/core.clj
Original file line number Diff line number Diff line change
@@ -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)])
)
Original file line number Diff line number Diff line change
@@ -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))))

0 comments on commit ddeff1a

Please sign in to comment.