Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What makes an exchange rate hard to predict?

Answered: 1 week ago