I am new to lisp so I apologize if advance it this is a simple question.
I have a list:
(set ‘inventory ‘(parts
((item 1001) (shoes (color brown) (size 10) (cost 20)))
((item 2011) (skirt (color blue) (size 4) (cost 10)))
((item 2120) (pants (color white) (size 32) (cost 30)))
((item 2121) (pants (color brown) (size 34) (cost 30)))))
I am trying to write a function that looks through the list by item number and return the correct one.
(findItem 1001 inventory)
should return:
((item 1001) (shoes (color brown) (size 10) (cost 20)))
This is what I have so far:
(defun findItem (q i)
(cond
((null q)
nil)
((null (cdr i))
nil)
((eq `parts (car i))
(findItem q (cdr i)))
((eq q (cdr (car (car i))))
(car i))
(T
(findItem q (cdr i)))))
Everything seems to work except ((eq q (cdr (car (car i)))) (car i))
(cdr (car (car i)))
should return (1001) or the part number
But the eq does not evaluate to true so the function overall returns nil.
And help would be appreciated