Write stream analogues of list processing functions, Data Structure & Algorithms

 (a) Write (delay ) as a special form for (lambda () ) and (force ), 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-nullfi 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

For example, if you have defined a stream of even integers called evens, you can display the first 50 even integers as follows:

(stream-for-each (lambda (x) (display x)(display " ")) (first 50 evens)).

Test your functions convincingly!

(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 (primefi n) that tests for primality and use it to create

 

Posted Date: 3/30/2013 3:41:17 AM | Location : United States







Related Discussions:- Write stream analogues of list processing functions, Assignment Help, Ask Question on Write stream analogues of list processing functions, Get Answer, Expert's Help, Write stream analogues of list processing functions Discussions

Write discussion on Write stream analogues of list processing functions
Your posts are moderated
Related Questions
Q. Develop a representation for a list where insertions and deletions can be done at either end. Such a structure is known as a Deque (Double ended queue). Write functions for inse

Q. Create a heap with the given list of keys: 8, 20, 9, 4, 15, 10, 7, 22, 3, 12                                                  Ans: Creation

Comparison Techniques There are several techniques for determining the relevancy and relative position of two polygons. Not all tests may be used with all hidden-surface algori

What do you understand by tree traversal? The algorithm walks by the tree data structure and performs some computation at everynode in the tree. This process of walking by the

What is Class invariants assertion A class invariant is an assertion which should be true of any class instance before and after calls of its exported operations. Generally

This section prescribes additional exercise with the recursive and iterative handling of a binary search tree. Adding to the Binary Search Tree Recursively Add implementation

Merge sort is also one of the 'divide & conquer' classes of algorithms. The fundamental idea in it is to split the list in a number of sublists, sort each of these sublists & merge

MID SQUARE METHOD

Q. Consider the specification written below of a graph G V(G ) = {1,2,3,4} E(G ) = {(1,2), (1,3), (3,3), (3,4), (4,1)} (i)        Draw the undirected graph. (

Write an algorithm for binary search. What are its limitations? .