Hy, bug fixing on the phonebook.

Table of Contents

bugfix.jpg
credit

1 Continuing Onwards.

The code I have already written seems to have a bug, namely it takes the input and replaces all the content in the file with the new input, meaning right now my phonebook will never contain more than one name. This is sad, and unfortunately not very useful, so now we will hunt the bug.

(defn add-field [name phone email]
  (process-new-input (. args name) :phone (. args phone) :email (. args email)))

This could be a source of a bug. Actually I think this is the bug, since it calls

which only creates the new structure, but it does not add to a structure.

Turns out replacing a single function in

Should fix the bug

(import argparse)
(defn search-database [n]
  (get data n))
(setv parser (argparse.ArgumentParser))
(.add_argument parser "-a" "--add" :help "Add a new field to the database" :default False :nargs "?")
(.add_argument parser "-e" "--email" :help "Populate the email field" :default "")
(.add_argument parser "-n" "--name" :help "Populate the name field")
(.add_argument parser "-p" "--phone" :help "Populate the phone field" :default 0)
(.add_argument parser "-q" "--query" :help "Query the database" :nargs "?" :dest "searching" :default False)
(setv args (.parse_args parser))
(setv data (load-database))
(cond
  [(= (. args add) None)
   (setv nam (. args name))
   (setv email (. args email))
   (setv phone (. args phone))
   (append-data nam phone email)
   (save-database)]
  [(= (. args searching) None)
   (setv n (. args name))
   (search-database n)]) ;; this turned out to be a bug.
(search-database n)

so using append-data instead should fix the bug I have been having. Therefore it should now be a minimal viable phonebook. But I still not to find another bug, since it says that there is a key error, so I need to stare at the code for a bit longer before I discover this malfunction.

Having had a little bit of a stare at the code, I discovered that in fact the bug resides here, so that should be rather simple to correct

(defn search-database [n]
  (get data n))

Since I used to use the variable with stars, but decided to change it, I seem to have forgotten this one As you probably see the code here is already implemented in the block up above. But it was a bug until I introduced this code to that block.

Now I have a different bug to hunt, no output when I query the phonebook after I add it. Turns out this should be a very simple bug, the search-database seems to just not actually print the value it finds.

In fact the print statement should be on the final cond

(print search-database n)

So in fact this code block should be the one in the big block not the one that is currently in that big block. After these few changes I think this is a viable phonebook, completely minimal.

H2
H3
H4
3 columns
2 columns
1 column
1 Comment
Ecency