Question: How would I write a stream in racket called weird-stream that is like the stream of natural numbers (i.e., 1, 2, 3, ...) except numbers

How would I write a stream in racket called weird-stream that is like the stream of natural numbers (i.e., 1, 2, 3, ...) except numbers divisible by 5 are negated (i.e., 1, 2, 3, 4, -5, 6, 7, 8, 9, -10, 11, ...). Due to the purpose of this exercise, we are not allowed to use racket functions such as 'stream' and this exercise is to be finished with functions such as cons, car, cdr, lambda, remainder functions. Some sample output could be

> (stream-until-n weird-stream 5) '(1 2 3 4 -5)

where stream-until-n presents first 5 values of the stream(weird-stream)

Then, how would I write a racket function called add-zero-to-stream that takes a stream `z` and returns another stream. If `x' would produce `z` for its *i-th* element, then `(add-zero-to-stream x)` would produce the dotted pair `(0 . z)` for its *i-th* element. Try using a thunk that when called uses both x and recursions.

If possible could I get the explanation for the answers too?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!