Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE DrRACKET to write for following functions 1.rotate: takes an integer n 0 and a list and rotates n elements off the front of the

USE DrRACKET to write for following functions

1.rotate: takes an integer n 0 and a list and "rotates" n elements off the front of the list onto the end.

E.g., > (rotate 3 '(1 2 3 4 5 6 7 8 9)) '(4 5 6 7 8 9 1 2 3)

2.lookup: treats a list of pairs as a lookup structure (aka "associative list"); when given a key and a list, it finds the pair whose car matches the key (using equal?) and returns the associated cdr. If no match exists, returns #f.

E.g., > (lookup 'a '((a . apple) (b . bee) (c . cat))) 'apple

> (lookup 'foo '((a . apple) (2 . "two")))

#f

3. update: updates or inserts a new pair into a lookup list (as used by lookup) reflecting a provided key/value mapping. (The location of a newly inserted pair doesn't matter.)

E.g.,> (update 'a 'apple '((b . bee) (c . cat))) '((b . bee) (c . cat) (a . apple))

4.equal-shape?: returns #t if two pairs have the same "shape", i.e., if their structure consisting of zero or more nested pairs is identical; returns #f otherwise.

E.g., > (equal-shape? '(1 2 3) '(2 3 4)) #t

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

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

In Problems 920, find the exact value of each expression. sec-11

Answered: 1 week ago