Question: USE LISP TO DO SOME PROGRAM 1.A triangular number or triangle number counts the objects that can form an equilateral triangle One can define a
USE LISP TO DO SOME PROGRAM
1.A triangular number or triangle number counts the objects that can form an equilateral triangle
One can define a function to compute the triangular number as:
|
| T(n) = 1 |
| if n = 1 |
|
| T(n) = n + T(n-1) |
| if n > 1 |
Create a Lips function that calculate the triangular number, e.g., (defun triangular-number (x))
To test your Lisp program, calculate (triangular-number 5) & (triangular-number 6)
2.Define a new function, called ismember, that returns TRUE if the atom is a member of a list, or FALSE otherwise, i.e.,: (defun ismember (atom list))
For instance:
(ismember a (1 2 3)) would return false
(ismember 1 (1 2 3) would return true
To quickly implement ismember you can take advantage of Lisp membership functions. As you know, list have several functions to handle lists. For instance, member, member-if, and member-if-not each search list for item or for a top-level element that satisfies the test. The argument to the predicate function is an element of list. If some element satisfies the test, the tail of list beginning with this element is returned; otherwise nil is returned.
3. Define a lisp function that calculates the size of a list called
(defun recursive-list-length (L) ...)
where (recursive-list-length '(1 2 3 5 7 11 13 17 19)) would be equal to 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
