I have this list
(define masterList(list redApple chickenLeg porkLoin milkD baguetteBread orangeJuice beanCan))
I am trying to make a function called lookup that will take an integer and return the element from the list that matches that integer. The list contains elements from a structure in this format
(define-struct storeItem (id des cost))
So I will be passing an integer that represents id and I want storeItem to be retuned.
For instance -
(define redApple (make-storeItem 0 "red delicious apple" 1.99))
If I searched masterList and passed it 0, I would expect redApple to be returned.
Any help on the syntax?
(define (contains masterList x)
(cond
((null? masterList) #f)
((eq? (car masterList) x) #t)
(else (contains (cdr masterList) x))))
This is what I am trying to make work.
It returns true/false correctly based on what I pass it.
(contains materList redApple) returns true.
How can I modify this to return redApple if 0 is entered?
;; These are the constructors to make the elements in our structure
(define redApple (make-storeItem 0 "red delicious apple" 1.99))
(define chickenLeg (make-storeItem 1 "boned chicken" 2.99))
(define porkLoin (make-storeItem 2 "processed pork" 4.99))
(define milkD (make-storeItem 3 "vitamin d milk" 3.99))
(define baguetteBread (make-storeItem 4 "french bread" 0.99))
(define orangeJuice (make-storeItem 5 "fruit juice drink)" 1.49))
(define beanCan (make-storeItem 6 "beans in a can" 2.49)
;; Creating a list that we will use as our master list which contains elements from our structure
(define masterList(list redApple chickenLeg porkLoin milkD baguetteBread orangeJuice beanCan))