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
Any binary search tree must contain following properties to be called as a red-black tree. 1. Each node of a tree should be either red or black. 2. The root node is always bl

In this unit, we discussed Binary Search Trees, AVL trees and B-trees. The outstanding feature of Binary Search Trees is that all of the elements of the left subtree of the root

Difference among Prism's and Kruskal's Algorithm In Kruskal's algorithm, the set A is a forest. The safe edge added to A is always a least-weight edge in the paragraph that lin

Explain the Assertions in Ruby Ruby offers no support for assertions whatever. Moreover, because it's weakly typed, Ruby doesn't even enforce rudimentary type checking on opera

The most common way to insert nodes to a general tree is to first discover the desired parent of the node you desire to insert, and then insert the node to the parent's child list.

Example 1:  Following are Simple sequence of statements Statement 1;  Statement 2; ... ... Statement k; The entire time can be found out through adding the times for

The class Element represents a single node that can be part of multiple elements on a hotplate and runs in its own thread. The constructor accepts the initial temperature and a hea

I need a recursive algorithm to implement the FIRST function to any grammar

Ans: A procedure to reverse the singly linked list: reverse(struct node **st) { struct node *p, *q, *r; p = *st; q = NULL; while(p != NULL) { r =q;

Question 1 Discuss the following theorems with respect to Splay Trees- Balance Theorem Dynamic Finger Theorem   Question 2 Write a C program for implementation