Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started