Browse Source

Basic PoC working

Simon Watson 2 years ago
parent
commit
789dcd052a
1 changed files with 24 additions and 10 deletions
  1. 24 10
      fin-lisp.lisp

+ 24 - 10
fin-lisp.lisp

@@ -11,6 +11,9 @@
 ;;; and the value is the monthly expenses hash
 (defvar *records* (make-hash-table :test 'equalp))
 
+(defun reset-records ()
+  (setf *records* (make-hash-table :test 'equalp)))
+  
 ;; Called like: (add-month '202107)
 (defun add-month (month-key)
   (setf (gethash month-key *records*) (make-hash-table :test 'equalp))
@@ -32,10 +35,6 @@
   (if (gethash month *records*)
       (let ((innerhash (gethash month *records*))
 	    (exp-l (prompt-for-expense)))
-	(format t "Expense name is: ~a" (first exp-l))
-	(terpri)
-	(format t "Expense value is: ~a"(second exp-l))
-	(terpri)
 	(setf (gethash (first exp-l) innerhash) (second exp-l)))
       ;;NIL))
       (add-expense-to-month (add-month month))))
@@ -66,11 +65,26 @@
 
 ;; Entry point
 (defun main ()
-  (format t "Available options:")(terpri)
-  (format t "1. Enter expense")(terpri)
-  (format t "2. Display month")(terpri)
-  (format t "3. Write records")(terpri)
+  (format t "Available options:~C" #\linefeed)
+  (format t "1. Enter expense~C" #\linefeed)
+  (format t "2. Display month~C" #\linefeed)
+  (format t "3. Write records~C" #\linefeed)
+  (format t "4. Read records~C" #\linefeed)
+  (format t "5. Quit~C" #\linefeed)
   (let
       ((answer (prompt-read "Select an option")))
-    answer))
-	      
+    (if (string= answer "1")
+	(add-expense-to-month
+	 (read-from-string
+	  (prompt-read "Enter month"))))
+    (if (string= answer "2")
+	(dump-month
+	 (read-from-string
+	  (prompt-read "Enter month"))))
+    (if (string= answer "3")
+	(serialize-records (prompt-read "Enter filename")))
+    (if (string= answer "4")
+	(deserialize-records (prompt-read "Enter filename")))
+    (if (string= answer "5")
+	(quit)))
+  (main))