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
What is quick sort? Quick sort is a sorting algorithm that uses the idea if split and conquer. This algorithm chooses an element called as pivot element; search its position in

Implement multiple queues in a single dimensional array. Write algorithms for various queue operations for them.

What is Efficiency of algorithm? Efficiency of an algorithm can be precisely explained and investigated with mathematical rigor.  There are two types of algorithm efficiency

What are the properties of an algorithsm?

1) Which graph traversal uses a queue to hold vertices which are to be processed next ? 2) Which of the graph traversal is recursive by nature? 3) For a dense graph, Prim's a

What are the expression trees? Represent the below written expression using a tree. Give a relevant comment on the result that you get when this tree is traversed in Preorder,

Ordinary variable An ordinary variable of a easy data type can store a one element only

how can i delete from deque while deletion is restricted from one end

what algorithms can i use for the above title in my project desing and implmentation of road transport booking system

Determine the effect of Ruby in implementation of string Ruby has a String class whose instances are mutable sequences of Unicode characters. Symbol class instances are charact