CS3723 HW6 Lisp solution

$24.99

Original Work ?

Download Details:

  • Name: HW6-ieppas.zip
  • Type: zip
  • Size: 20.73 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (10 votes)

 

  1. Code the function, removeNILTop, which is passed a list and removes NIL at the top level.

Examples:

> (removeNILTop ‘(NIL X NIL NIL Y NIL Z))

(X Y Z)

> (removeNILTop ‘(X NIL Y NIL Z NIL))

(X Y Z)

> (removeNILTop ‘(NIL (X NIL Y) (NIL NIL)))

((X NIL Y) (NIL NIL))

 

  1. Code the function, removeNILMost, which is passed a list and removes NIL at any level. Note: if the result of removing NIL gives a NIL, it is unnecessary to remove that resulting NIL. (See the extra credit.)

Examples:

> (removeNILMost ‘(NIL X NIL NIL Y NIL Z))

(X Y Z)

> (removeNILMost ‘(X NIL (Y NIL Z) NIL))

(X (Y Z))

> (removeNILMost ‘(NIL (NIL) (X NIL Y) (NIL NIL) Z))

(NIL (X Y) NIL Z)

> (removeNILMost ‘(NIL ((((((NIL) NIL)))))))

((((((NIL))))))

 

  1. Code the function, reverseTop, which is passed a list and returns a reversed list of the high-level entries. Do not use the built-in REVERSE function.

Hint:  APPEND could be useful.

Examples:

> (reverseTop ‘(X Y Z))

(Z Y X)

> (reverseTop ‘(X (Y Z (A)) (W)))

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

 

  1. Code the function, reverseAll, which is passed a list and returns a reversed list at all levels.

Examples:

> (reverseAll ‘(X Y Z))

(Z Y X)

> (reverseAll ‘(X (Y Z (A)) (W)))

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

 

  1. Code the function, palindrome, which is passed a list and returns T if the list is a palindrome; otherwise, it returns NIL. It only needs to be a palindrome at the top-level.

Examples:

> (palindrome ‘(R A C E C A R))

T

> (palindrome ‘(W A S I T A C A R O R A C A T I S A W))

T

> (palindrome ‘(N I X O N))

NIL

 

Extra credit: (5 pts)

Code the function removeNILAll which also removes any resulting NIL (except the single outermost)

> (removeNILAll ‘(NIL (NIL) (X NIL Y) (NIL NIL) Z))

((X Y) Z)

> (removeNILAll ‘(NIL ((((((NIL) NIL)))))))

NIL

 

To receive extra credit:

  • removeNILAll must work for all possible cases.
  • The other functions must work for all possible cases.
  • All your functions must be properly documented.
  • Your submission MUST NOT be late.
  • There is an extra file to run your code that includes extra credit cases named “hw6LispExtraRun.txt”