LISP code for Q#2 [total of pt extra credit] For question 2 I pointed at writing a wrapper function to deal with the parts designation.
LISP code for Q#2 [total of pt extra credit]
For question 2 I pointed at writing a wrapper function to deal with the parts designation. If instead, you handle the parts designation for each of the three functions: findItem (a), findSize (b) and findColor (c) in that function (i.e. aside from helper functions such as getItemNum, getSize or getColor you dont write any additional functions for each) you will receive point extra credit.
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
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started