Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the following stream related questions you may begin with these definitions:

ID: 3677491 • Letter: F

Question

For the following stream related questions you may begin with these definitions: Write stream analogues of some familiar list processing functions: (stream-ref str n) -- returns the nth element in stream str (stream-filter pred str) -- makes a new stream of elements satisfying pred (stream-map proc str) -- applies proc to each element of str (first n str) -- makes a new stream of the first n items in str (list right arrow stream lis) -- makes a stream from list lis (stream right arrow list str) -- reverse of above (assume str is finite) Write stream generators to help test the above functions: an infinite stream of l's an infinite stream of all odd integers an infinite stream of random numbers between 1 and 100 an infinite stream of the values of function f(n) = f(n - l) + 2f(n - 2) + 3f(n - 3) (given f(n) = n iff n

Explanation / Answer

A)

   procedure: (stream-ref stream n)
{} × nat
Stream-ref returns the nth element of stream, counting from zero. An error is signaled if n is greater than or equal to the length of stream.

(define (fact n)

(stream-ref

    (stream-scan * 1 (stream-from 1))

    n))

(stream-range 0 10) 0 1 2 3 4 5 6 7 8 9

(stream-range 0 10 2) 0 2 4 6 8

     v.            procedure: (list->stream list-of-objects)
[] {}
List->stream takes a list of objects and returns a newly-allocated stream containing in its elements the objects in the list. Since the objects are given in a list, they are evaluated when list->stream is called, before the stream is created. If the list of objects is null, as in (list->stream '()), the null stream is returned. See also stream.

(define strm123 (list->stream '(1 2 3)))

We obtain a stream with always the same number. This is similar to the definition of ones. (define (make-random-stream) (cons-stream (random 100) (make-random-stream)))

We obtain a stream of different random numbers. If the stream is memoized, the sequence of numbers stays the same. If we do not memoize, then the value of a particular element in the stream will be different each time we read it with stream-car.

I took the reference

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote