Answered step by step
Verified Expert Solution
Question
1 Approved Answer
SICP in Scheme Appendix 1 shows a Scheme definition for a simple Item object which could be used in an inventory system. An item object
SICP in Scheme
Appendix 1 shows a Scheme definition for a simple Item object which could be used in an inventory system. An item object consists of a name and stock which tracks how many of that particular item are in the inventory. (a) Write down a Scheme expression to create an item, B1 with a name of "Ale", and an inital stock of 10. Please note that you can represent the name using either a String or a quoted-literal. That is, as "Ale" or 'Ale [2 marks] (b) To increase the stock of item B1 by five, the following expression is needed ( (B1 'addItems) 5) Many people find this notation confusing: write a scheme procedure increaseStock, which accepts two arguments: an item name and an amount. It can then be used thus: (increaseStock B1 5,) [3 marks] (c) i. Draw an environment diagram which shows the state of the sys tem after B1 from part (a) has been defined. [4 marks] ii. Now extend your diagram from part (i) to depict the evaluation of (define adder (B1 'addItems)). [3 marks] iii. Finally, extend your diagram to depict the evaluation of (adder 5) which will increase the stock of item B1 by five. [2 marks] Appendix 1 shows a Scheme definition for a simple Item object which could be used in an inventory system. An item object consists of a name and stock which tracks how many of that particular item are in the inventory. (a) Write down a Scheme expression to create an item, B1 with a name of "Ale", and an inital stock of 10. Please note that you can represent the name using either a String or a quoted-literal. That is, as "Ale" or 'Ale [2 marks] (b) To increase the stock of item B1 by five, the following expression is needed ( (B1 'addItems) 5) Many people find this notation confusing: write a scheme procedure increaseStock, which accepts two arguments: an item name and an amount. It can then be used thus: (increaseStock B1 5,) [3 marks] (c) i. Draw an environment diagram which shows the state of the sys tem after B1 from part (a) has been defined. [4 marks] ii. Now extend your diagram from part (i) to depict the evaluation of (define adder (B1 'addItems)). [3 marks] iii. Finally, extend your diagram to depict the evaluation of (adder 5) which will increase the stock of item B1 by five. [2 marks]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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