Hi!
I have 2 files in my clojure project.
The first one (db.clj) reads into a txt file and store the data into a list of vectors and the second one (menu.clj) shows a menu with many options.
My conditions work : tables are displayed as wanted, however I get an awkward error at the end and my app stops running.
Details :
db.clj :
(ns db)
(defn load-data
[filename]
(with-open [rdr (io/reader filename)]
;; https://clojuredocs.org/clojure.core/doall
(doall
(for [line (line-seq rdr)
:let [[id & data] (clojure.string/split line #"\|")]]
[(Integer/parseInt id)
data]))))
menu.clj :
(ns menu
(:require [db])
)
(def customers (db/load-data "cust.txt"))
(def products (db/load-data "prod.txt"))
(def input_ 0) ; initialize input
(defn menu
[]
(if (not= input_ "6")
(do
(newline) ; insert a new line
(println " ** MENU ** ") ; display menu
(println "
1. Display Customer Table
2. Display Product Table
3. Display Sales Table
4. Total Sales for Customer
5. Total Count for Product
6. Exit")
(println "Enter an option > ")
(flush)
(def input_ (read-line)) ; put the input in input_ variable
(cond
(= input_ "1")
((println "Table of customers: ")
; run >> every item in a newline
(run! println (db/load-data "cust.txt")))
(= input_ "2")
((println "Table of products: ")
; run >> every item in a newline
(run! println (db/load-data "prod.txt")))
:else (println "Option not handled!")
)
;(println (str "The option entered is: \"" input_ "\""))
(menu))
(println "Goodbye!") ; If user prompts 6
))
Console :
** MENU **
1. Display Customer Table
2. Display Product Table
3. Display Sales Table
4. Total Sales for Customer
5. Total Count for Product
6. Exit
Enter an option >
2
Table of products:
[1 (shoes 14.96)]
[2 (milk 1.98)]
[3 (jam 2.99)]
[4 (gum 1.25)]
[5 (eggs 2.98)]
[6 (jacket 42.99)]
Syntax error (NullPointerException) compiling at (menu.clj:42:1).
null
Full report at:
/tmp/clojure-4521524603536338044.edn
Thanks!