Recursive double function

Assignment Help Programming Languages
Reference no: EM13312187

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

Reference no: EM13312187

Questions Cloud

Find who has more momentum : A 100 kg running back carries the ball forward with a speed of 9 m/s. He is hit head on in the air at the goal line by a 130 kg defensive back running in the opposite direction at 7 m/s
Determine what is the expected cycle service level : Demand for a particular product is normally distributed with a mean of 100 units and a standard deviation of 20 per period. if there are 120 units in inventory at the beginning of this period
Find the magnitude of the average force acting on the ball : An object of mass 0.77 kg is initially at rest. When a force acts on it for 2.9 ms it acquires a speed of 16.2 m/s. Find the magnitude of the average force acting on the ball
Determine the specific speed ad brake horsepower : The 35-in pump of fig. 11.7b is used to pump 24000 GPM of water (68ft) at 710 rpm from a large tank whose surface is at atmospheric presure. the head loss from tank to the pump inlet is 3ft.
Recursive double function : 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 and
How much calcium bicarbonate will need to be added : How much calcium bicarbonate (kg/day) will need to be added per day in water with alkalinity of 30 mg/L CaCO3 (assume for simplicity only bicarbonate alkalinity is present) if 794 kg of (Al2(SO4)3 x 18H20 is added per week
What is the car doing at that instant : A car is moving in a circular path. At a certain instant, it has zero tangential acceleration and a non-zero centripetal acceleration
Explain how to estimate the flow rate of water : the pressure drop over 15 m of 2-cm diameter galvanized iron pipe is measured to be 60 Pa. If the pipe is horizontal, estimate the flow rate of water. use for water v=10^-6 m^2/s and density of water = 1000kg/m^3
Business research in order to forecast and predict purposes : Multiple regression analysis is widely used in business research in order to forecast and predict purposes. It is also used to determine what independent variables have an influence on dependent variables, such as sales.

Reviews

Write a Review

Programming Languages Questions & Answers

  Program to create three identical list

Write a program to create three identical list, list1, list2, and list3, of 5000 elements. The program then sorts list1using quick sort, list 2 using insertion sort.

  Describe how to create users for sales organization unit

Describe how you would create users for sales organization unit and how you can set up user groups in this particular situation (global, universal, domain local).

  Create logic for program which contains housekeeping

Create logic for program in pseudocode or flowchart which contains housekeeping, detail loop, and end-of-job modules, and which computes service charge and the original check amount customers owe for writing bad check.

  Write a vhdl code for soda vending machine

Write a VHDL code that implements the above soda machine. You have to turn in the following: A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

  Php code to add-delete product using ajax programming

PHP Code to add a new product and delete a existing product Implement AJAX Programming based solutions to write code to add a new product to the database.

  Find x from n by n matrix of sorted integers

We want to find out if x is present in M.  It is straightforward to do this in O(n log n) time. Explain such algorithm. (b) Can you do better? Describe your solution

  Explain about lexical analyzer

Explain about Lexical Analyzer

  Use for loop to calculate sum of squares of numbers

Given int variables k and total which have already been declared, use the for loop to calculate sum of squares of first 50 counting numbers, and store this value in total.

  Program to calculate cost of purchase-requests from user

Program calculates cost of purchase, requests another item selection from user, and so on. User enters 0 from item menu to quit.

  Write program to enter numeric values-arithmetic operator

Write a program that lets the user enter 2 numeric values, and an arithmetic operator: +, -, * and /. Write a switch statement that displays the result.

  Provide unoptimized-optimized prefix using recursive rule

Where the recursive rule uses concatenation of strings, so F2 is "ab", F3 is "aba". Note that the length of Fn is the nth Fibonacci number. Provide unoptimized and optimized ‘prefix' (fail) function for F7.

  Program to calculate and displays number of miles per hour

Design a program to calculate and displays the number of miles per hour over the speed limit that a speeding driver was doing

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd