The Association-List Assignment
Write me two functions ... get and set
Get should take two arguments. The first is an element
known as the key, the second is a list in association list format.
If the a-list contains a tuple with the key, get should return the value
associated with that key. Otherwise, get should return null.
This is worth 5 points.
(get 'age '((age 3 )( size 10)) should return 10
(get 'age '((size 10) (growth yes)) should return '()
Set should take two arguments. The first is a tuple to
add to the a-list, and the second is an a-list.
-
If the key value of the given tuple is not found in the a-list, set should
return an a-list containing the previous contents and the tuple.
This is worth 2 points.
(set '(age 3) '((size 10)( heigth 4))) should return a list with
three elements: (age 3) (size 10) and (heigth 4) in any
order.
(set '(name randy) '((size 10)( heigth 4))) should return a list
with three elements: (name randy) (size 10) and (heigth 4) in
any order.
-
If the key value of the given tuple is found in the list, set should return
the given list with the new tuple. The key value should only be listed
once, not twice. This is worth 3 points.
(set '(age 3) '((age 2) (size 10))) should return a list with
three elements: (age 3) (size 10) and (heigth 4) in any order.
It should NOT return any list with age listed twice.