;3.6 Functions for maintaining table ;Adam Nelson ;Chet Tobrey ;;;using association list (setf state-table '((AL . Alabama)(AK . Alaska)(AZ . Arizona)(AR . Arkansas))) ;;;;;using a hash-table (setf table(make-hash-table)) (setf (gethash 'AL table) 'Alabama) (setf (gethash 'AK table) 'Alaska) (setf (gethash 'AZ table) 'Arizona) (setf (gethash 'AR table) 'Arkansas) ;;;;property lists (setf (get 'AL 'state) 'Alabama) (setf (get 'AK 'state) 'Alaska) (setf (get 'AZ 'state) 'Arizona) (setf (get 'AR 'state) 'Arkansas) (setf (get 'Arizona 'abbrev) 'AZ) (setf (symbol-plist 'state-table) '(AL Alabama AK Alaska AZ Arizona AR Arkansas)) (egs :3.6 (eg '(print state-table) :of "here is the table we are working with. It is a list of dotted pairs where each pair has a key and a value" :out '((AL . ALABAMA) (AK . ALASKA) (AZ . ARIZONA) (AR . ARKANSAS))) (eg '(assoc 'AK state-table) :of "using assoc to look up a state by it two letter abbreviation." :out '(AK . ALASKA)) (eg '(cdr (assoc 'AK state-table)) :of "using cdr and assoc to return only the state name given its two letter abbreviation." :out 'ALASKA) (eg '(assoc 'TX state-table) :of "looking up a pair that is not in the table" :out 'TEXAS) (eg '(rassoc 'Arizona state-table) :of "Using rassoc to search the table by value rather than by key" :out '(AZ . ARIZONA)) (eg '(car(rassoc 'Arizona state-table)) :of "using car on the previous function to return only the two letter abbrev. when given the value of the pair" :out 'AZ) ;;;;;HASH TABLE HERE (eg '(gethash 'AK table) :of "using gethash to access the hash-table" :out 'ALASKA) (eg '(gethash 'TX table) :of "if only there was a texas" :out 'TEXAS) ;;;;Property list (eg '(get 'AK 'state) :of "retrieving values from the property list" :out 'ALASKA) (eg '(get 'TX 'state) :of "still no Texas" :out 'TEXAS) (eg '(get 'state-table 'AK) :of "property lists" :out 'ALASKA) (eg '(get 'state-table 'Alaska) :of "property list example" :out 'AK))