Question: In Lisp 2. Code the function ( replaceIn list possibleList repValue ) which constructs a new list. It examines list for occurrences of any of

In Lisp

2. Code the function (replaceIn list possibleList repValue) which constructs a new list. It examines list for occurrences of any of the atoms from the possibleList. Those are replaced with repValue. This only examines the top-level items in list.

Example:

> (replaceIn '(P A T T E R) '(T R) 'S)

(P A S S E S)

3. Code the function (insertAfter list atm insValue) which constructs a new list by inserting the specified insValue into the list after each top-level occurrence of the specified atm.

Example:

> (insertAfter '(H O H O) 'H 'X)

(H X O H X O)

> (insertAfter '(H O H O) 'W 'X)

(H O H O)

4. Code the function (insertNth list N insValue) which constructs a new list by inserting the specified insValue into the list after 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)

5. Code the function (insertAfterAll list atm insValue) which constructs a new list by inserting the specified insValue into the list after all occurrences of the specified atm. This includes any level of nesting.

Example:

> (insertAfterAll '(X (X Y X) X Z) 'X 'W)

(X W (X W Y X W) X W Z)

> (insertAfterAll '((X (X (Y X)) X) Z) 'X 'W)

((X W (X W (Y X W)) X W) Z)

6. Code the function, (atomicList list), which is passed a list that can have embedded lists. It should return a list of atoms that occur anywhere in the list regardless of nesting.

Hint: APPEND can be useful.

Examples:

> (atomiclist '(A (B F (H) G) J))

(A B F H G J)

> (atomiclist '(L () (I () S) (((P ()))) ))

(L NIL I NIL S P 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!