1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nuetrik [128]
4 years ago
6

Code the function (insertNth list N insValue) which constructs a new list by inserting the specified insValue into the list afte

r the Nth top-level value (relative to 1).Example:> (insertNth '(X Y Z) 2 'FUN)(X Y FUN Z)> (insertNth '(X Y Z) 4 'FUN)(X Y Z)
Computers and Technology
1 answer:
-BARSIC- [3]4 years ago
3 0

Answer:

Explanation:

Function algorithm is coded below

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2. Replace in Function

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(defun replace-all (string part replacement &key (test #'char=))

 "Returns a new string in which all the occurrences of the part is replaced with replacement."

 (with-output-to-string (out)

   (loop with part-length = (length part)

         for old-pos = 0 then (+ pos part-length)

         for pos = (search part string

                           :start2 old-pos

                           :test test)

         do (write-string string out

                          :start old-pos

                          :end (or pos (length string)))

         when pos do (write-string replacement out)

         while pos)))

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

3. Insert After

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(defun insert-after (lst index newelt)

(push newelt (cdr (nthcdr index lst)))

lst)

(insert-after '(a c d) 0 'b) => (A B C D)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

4. insertNth

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(defun insertNth(number index list)

 (do ((head '() (list* (first tail) head))

      (tail list (rest tail))

      (index index (1- index)))

     ((zerop index)

      (nreconc head (list* (+ number (first tail))

                           (rest tail))))))

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

5. InsertAfterAll

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(defun InsertAfterAll (a v)

  (if (null v) (cons a nil) (cons (car v) (endcons a (cdr v)))))

(endcons 'a '(b c d))

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

You might be interested in
In Microsoft Word, when you highlight existing text you want to replace, you are in
Andreyy89
<span>In Microsoft Word, when you highlight existing text you want to replace, you are in insert mode. You know if you are in insert mode if</span><span> you see the word "Insert" in the Status bar and any text you paste in will push aside text on either side of the cursor.</span>
6 0
4 years ago
The term “computer literacy” dates back to what decade? <br> 1960s<br> 1970s<br> 1980s<br> 1990s
NNADVOKAT [17]
1970-80s which is when some of the first computers were created like apple computers which looked like a giant cube and a rectangle on the side which is very different than what we have today.

Hope this helps!
3 0
4 years ago
When a pitcher is holding a baseball, the ball has ______energy.
MA_775_DIABLO [31]
Answer would be D)potential
3 0
3 years ago
Read 2 more answers
How are special characters added to a Word document? Check all that apply.
MrRissso [65]

It kinda depends on what you mean by special characters

7 0
3 years ago
Read 2 more answers
WILL GIVE BRAINLIEST ANSWER!!!<br><br> How do you manage your screen time?
Aloiza [94]
You can set it up in settings and set strict hours for screen time.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Write the code to declare a variable to hold the value of the grade you hope to get in this class. What stdio.h input function w
    13·1 answer
  • A written guarantee to fix or replace an item is called a _____.
    5·2 answers
  • How to calculate a pid controller
    8·1 answer
  • Rate monotonic Analysis (RMA) is a model for predicting whether or not a system will meet its timing as well as throughput requi
    6·1 answer
  • The large program that controls how the CPU communicates with other components is the​
    9·1 answer
  • The concept of the internet was developed by the u.s. department of defense as a network that ________ in event of an attack.
    8·1 answer
  • Vocational counselors group career and occupation specialties into <br> career clusters.
    12·1 answer
  • Edhesive assignment 1 movie ratings
    9·1 answer
  • What is an algorithm?
    11·1 answer
  • 1. My grandma and I went shopping to look for old
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!