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
(a) Explain the term Group Support System and elaborate on how it can improve groupwork. (b) Briefly explain three advantages of simulation. (c) Explain with the help of a

Thus far, we have seen the demonstration of a single queue, but several practical applications in computer science needs several queues. Multi queue is data structure in which mult

If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Explain the representations of graph. The different ways of representing a graph is: Adjacency list representation : This representation of graph having of an array Adj of

When writing a code for a program that basically answers Relative Velocity questions how do you go at it? How many conditions should you go through?

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

Q. Explain the technique to calculate the address of an element in an array. A  25 × 4  matrix array DATA is stored in memory in 'row-major order'. If base  address is 200 and

The Space - Time Trade Off The best algorithm to solve a given problem is one that needs less space in memory and takes less time to complete its implementation. But in practic

1. A string s is said to be periodic with a period α, if s is α k for some k > 2. (Note that α k is the string formed by concatenating k times.) A DNA sequence s is called a tand

Explain the term totalling To add up a series numbers the subsequent type of statement must be used: Total = total + number  This literally means (new) total = (old) t