Write a procedure that produces independent stack objects

Assignment Help Computer Engineering
Reference no: EM13737

(1) Sort a list of distinct numbers in ascending order, using the following divide-and-conquer strategy (Quicksort): divide the list of numbers into two lists: one that contains all items that are strictly smaller than the first item (often called the pivot), and another with all those items that are strictly larger than the first item.

Then the two smaller lists are sorted using the same procedure. Once the two lists are sorted, the pieces are juxtaposed.

(2) Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

(define stack1 (make-stack))  
(define stack2 (make-stack))

Write procedures to manipulate stacks, e.g.

(stack1 'empty?)  ==>  boolean
(stack1 'push! item)  ==> pushes item on top of stack
(stack1 'top)  ==> returns top element of stack, leaves stack unchanged
(stack1 'pop!) ==> throws away top element of stack
(stack1 'print) ==> prints some representation of the stack from top to bottom, enclosed in brackets etc....

Your tests should include making several stacks, pushing on one what is popped from the other, attempts to pop from an empty stack etc.

Also write a procedure to reverse a list by using two stacks.

(3) Implement your own streams.

(a) Write (delay <expr>) as a special form for (lambda () <expr>) and (force <expr>), as discussed in class.

(b) Write (stream-cons x y) as a special form, as discussed in class.

(c) Write stream analogues of some familiar list processing functions, including:

(stream-car str)
(stream-cdr str)
(stream-null? str)
(stream-ref str n) --- returns the nth element in stream str
(stream-filter pred str)    --- makes a new stream of elements satisfying pred
(stream-for-each proc str) --- applies proc to each element of str for side effect
(first n str)    --- makes a stream of the first n items in str
(list->stream lis) --- makes a stream from list lis
(stream->list str) --- opposite coercion

(d) Now define a bunch of streams to test your functions:

(i) an infinite stream of 1's
(ii) an infinite stream of all even integers
(iii) an infinite stream of random numbers between 1 and 100

(iv) write a predicate (prime? n) that tests for primality and use it to create a stream of all primes

(4) (i) Add the special form let to the metacircular interpreter

(ii) What changes are needed in the metacircular interpreter so that Scheme uses dynamic instead of lexical scoping?

Reference no: EM13737

Questions Cloud

Elevating the service experience : Elevating the Service Experience
The frantic pipe layer game : Design the Frantic Pipe Layer game
History of imperialism and colonialism : Discuss the specific connections between economic development and imperialism in the latter half of the 20th century.
What the general rules are for agricultural produce : Review and Explain what the general rules are for agricultural produce using US GAAP and IFRS.
Write a procedure that produces independent stack objects : Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.
Write a business proposal for a new product : Write a business proposal for a new product or service that your company will launch.
Sample website project : This website consists of three sections: a narrative, a storyboard, and a business Website.
Gravity conveyor : Illustrate the cause of the components accelerating from rest down the conveyor.
Design a gui and implement tic tac toe game in java : Design a GUI and implement Tic Tac Toe game in java

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Security policy document project

Analyze security requirements and develop a security policy

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd