Part 1: The Double Functions
Write the following three functions.
double-recursive (y)
double-iterative (y)
double-mapcar (y)
each of these returns the list consisting of each element of list y in a list has been replaced by two copies of the elements. For example,
(double-recursive '(1 2 3))
returns
(1 1 2 2 3 3)
If y is not a list, then nil is returned.
These double functions work only at the top-level; For example,
(double-recursive '(1 (2 3) 4))
returns
(1 1 (2 3) (2 3) 4 4)
Note how the top-level elements are duplicated, but the elements of nested lists are not. double-recursive is to be written recursively, double-iterative is to be written iteratively using either ‘go' or ‘do', and double-mapcar is to be written using ‘mapcar'. Hint: for dou- ble-mapcar,use the "apply-append trick" (see text).
Part 2: The Recursive Double Function
Write the function
rdouble (y)
On non-nested lists, it behaveslikethe double functions above.Onnested lists, however, it returns a list of duplicates of the inner elements. Forexample,
(rdouble '(1 (2 3) 4))
returns
(1 1 (2 2 3 3) 4 4)
rdouble is to be written recursively (no iteration is allowed). Hint: use car-cdr recursion.
Part 3: The my-mapcar Function
Write the function
my-mapcar (fun l1 l2)
it behavesexactly as mapcar using fun with argument lists l1 and l2. Assume that my-map- car is invokedonly with the twoargument lists and that fun can be evaluated on twoargu-ments. Write my-mapcar recursively.Use no iteration or mapping functions
Attachment:- PL_Question.zip