Hy, bug fixing on the phonebook.
Table of Contents
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.
Leave Hy, bug fixing on the phonebook. to:
Read more #hive-169321 posts
Best Posts From iobates
We have not curated any of iobates's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From iobates
- Bitcoin vs CBDC
- A quick Tactic from a game.
- Ads making a site useless
- Having Started my fitness training I was a bit sore for a few days.
- Carnivore diet 27 August 2024
- Carnivore 26 August
- Hiring practice at IBM will destroy the company.
- Carnivore 25 august
- Carnivore 24th August 2024
- Carnivore 23 August 2024
- Carnivore diary for 22nd of August 2024. Some benefits from the diet as well.
- Carnivore Diary 21st Aug
- Carnivore Diary 20th of August 2024
- A gem from a blindfold game
- Chess problem, from a game
- Tracking pill use, a simple CLI tool
- update to the unpacker, delete the archives when unpacking completes; it works but I think it has a few bugs.
- AI: Hype-train, is it finally over ?
- A Small Program to extract Archives
- Blindfold game analysis