question 1 an accumulator is a procedure that is


Question 1

An accumulator is a procedure that is called repeatedly with a single numeric argument and accumulates its arguments into a sum. Each time it is called, it returns the currently accumulated sum. Write a procedure make-accumulator that generates accumulators, each maintaining an independent sum [2 marks]. The input to make-accumulator will correctly specify the initial value of the sum; for example

(define A (make-accumulator 5))
(A 10)
15
(A 10)
25

Question 2

Write a procedure (make-queue) that produces independent first-in-first-out queue objects, using a message-passing style.

For example:
(define queue1 (make-queue))
(define queue2 (make-queue))

Write procedures to manipulate queues.

1. (queue1 'empty?): boolean

2. (queue1 'enqueue! item): adds item to the queue

3. (queue1 'front): returns the next element of the queue that would be removed on dequeue

4. (queue1 'back): returns the last element of the queue that would be removed on dequeue (i.e. the most recent element added)

5. (queue1 'dequeue!): throws away the front element

6. (queue1 'print): prints some representation of the queue from front to back

Request for Solution File

Ask an Expert for Answer!!
Application Programming: question 1 an accumulator is a procedure that is
Reference No:- TGS0501497

Expected delivery within 24 Hours