Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function cycle-lists that takes two lists, xs and ys, and returns a stream. The lists may or may not be the same

 

Write a function cycle-lists that takes two lists, xs and ys, and returns a stream. The lists may or may not be the same length, but you may assume they are both non-empty. The elements produced by the stream are pairs where the first part is from xs and the second part is from ys. The stream cycles forever through the lists. Your solution should not require the use of mutable state, i.e., it should not use set! . A constant-time ( O(1)) solution is possible. Examples: (stream-take-n 8 (cycle-lists '(1 2 3) '("a" "b"))) => ((1. "a") (2. "b") (3. "a") (1. "b") (2. "a") (3. "b") (1. "a") (2. "b")) Hint: Think about how you could create a stream that endlessly cycles through all the elements of a single, given list. You can use a local environment to store a copy of the list through which you must cycle and a helper function that uses this stored copy when it runs out of elements to cycle through.

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

Recommended Textbook for

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Computer Network questions

Question

What role do hormone levels play in mood?

Answered: 1 week ago

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago