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

Assignment Help:

 (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

 


Related Discussions:- Write stream analogues of list processing functions

Properties of red- black tree, Any Binary search tree has to contain follow...

Any Binary search tree has to contain following properties to be called as a red- black tree. 1. Each node of a tree must be either red or black. 2. The root node is always b

Linear search, Linear search is not the most efficient way to search an ite...

Linear search is not the most efficient way to search an item within a collection of items. Though, it is extremely simple to implement. Furthermore, if the array elements are arra

Full binary trees, Full Binary Trees: A binary tree of height h that had 2...

Full Binary Trees: A binary tree of height h that had 2h -1 elements is called a Full Binary Tree. Complete Binary Trees: A binary tree whereby if the height is d, and all of

C++, 7. String manipulation 7.a Write a C Program using following strin...

7. String manipulation 7.a Write a C Program using following string manipulation functions a) strcpy b) strncpy c) strcmp d) strncmp e) strlen f) strcat

Circular doubly link list, what is circular doubly link list?write down the...

what is circular doubly link list?write down the algorithm for insertion of elements in circular doubly link list

Explain the term totalling, Explain the term totalling To add up a ser...

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

What are the structures used in file-system implementation, What are the st...

What are the structures used in file-system implementation? Several on-disk and in-memory structures are used to execute a file system a. On-disk structure include P

Define a procedure called make-avl-tree, This question deals with AVL trees...

This question deals with AVL trees. You must use mutable pairs/lists to implement this data structure: (a) Define a procedure called make-avl-tree which makes an AVL tree with o

Program segment for deletion of any element from the queue, Program segment...

Program segment for deletion of any element from the queue delete() { int delvalue = 0; if (front == NULL) printf("Queue Empty"); { delvalue = front->value;

Write Your Message!

Captcha
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