Question: PLEASE READ QUESTION CAREFULLY. You have to do in LISP language not in any other language. 2). The interesting thing about LISP is that not
PLEASE READ QUESTION CAREFULLY. You have to do in LISP language not in any other language.
2). The interesting thing about LISP is that not only is it typeless, but it easily confuses code with data. For instance, we can quickly create a database of parts with the following list:
(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)))
)
If I want a variable to represent it, I simply stick this before and after:
> (set inventory
> (parts
> )
i.e. by quoting the parts list, I tell LISP that the word parts is an atom and not a function.
How would I access my inventory? Write the following functions. When writing code, only use these functions: defun, cond, car, cdr, list, cons, append, equal, and null. (DO NOT USE setq or set.)
|
| API (output below) |
| a) [1 pts] one that returns an entry by item number | > (findItem 1001 inventory) |
| b) [1 pts] one that returns first entry of a given size | > (findSize 32 inventory) |
| c) [2 pts] one that returns all items with a given color | > (findColor brown inventory) |
Some sample runs to help understand how function should work. Note inventory parts list will change (i.e. your functions need to work with different, longer list) so dont write function depending on the one given.
> (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)))))
>
> (findItem 1001 inventory)
> ((item 1001) (shoes (color brown) (size 10) (cost 20)))
>
> (findSize 32 inventory)
> ((item 2120) (pants (color white) (size 32) (cost 30)))
>
> (findColor brown inventory)
> (((item 1001) (shoes (color brown) (size 10) (cost 20)))((item 2121)
(pants (color brown) (size 34) (cost 30))))
>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
