Question: Using Common LISP , write a recursive function (REPLICATE L NLIST) which takes a list L and a list NLIST of integers (all of which

Using Common LISP, write a recursive function (REPLICATE L NLIST) which takes a list L and a list NLIST of integers (all of which can be assumed to be >= 0) and which uses NLIST as a "template" to produce a new list in whch each element of L is replicated the number of times specified in NLIST.

For example:

(REPLICATE '(A B C D E) '(1 0 4 3 2)) should return (A C C C C D D D E E),

(REPLICATE '(W X Y Z X Q W) '(3 4 0 1) should return (W W W X X X X Z),

(REPLICATE '(1 2 3 1) '(1 2 3 4 5 6)) should return (1 2 2 3 3 3 1 1 1 1),

(REPLICATE '(X W X E D R) nil) should return nil,

(REPLICATE nil '(1 0 0 3 2)) should return nil.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!