Question

Please help with all four questions regarding LISP Programming. Thank you.

Please answer all questions with output plesase.

LISP Programming Assignment
It is a good idea to start this assignment early; Lisp programming, while not inherently difficult, often seem somewhat foreign at first, particularly when it comes to recursion and list manipulation. This assignment is loosely based on material by Dr. Henri Casanova.  

Problem #1 Define a function that takes two arguments and returns the greater of the two.

Problem #2 Write a function called inches that accepts feet and inches and returns the equivalent length in centimeters. If x is the first argument and y is the second, the formula is 2.54(12x + y). For example,
USER(1): (inches 0 1)
2.54
USER(1): (inches 6 2.5)
189.22999999999999

Problem #3 - Remove an element from a list using Iteration  
Write a Common Lisp function called my-remove that takes an atom and a list in input, and returns a list that is identical to the input list, but with elements equal to the input atom removed, if any. Examples of the function in operation are shown below (user input is in red):
CL-USER(1): (my-remove 'b '(a b c b d)) (a c d) CL-USER(2): (my-remove 'b '(a c d e f)) (a c d e f) CL-USER(3): (my-remove 'a '(b (a d) a d)) (b (a d) d) CL-USER(4): (my-remove 'a '()) nil
Problem #4 - Remove an element from a list using Recursion  
Write a Common Lisp function called my-recursive-remove that takes an atom and a list in input, and returns a list that is identical to the input list, but with all occurrences of the input atom removed, if any. Examples of the function in operation are shown below (user input is in red):
CL-USER(1): (my-recursive-remove 'a '(a b c d)) (b c d) CL-USER(2): (my-recursive-remove 'a '((a b) a (c d e a) (a a) b)) ((b) (c d e) nil b)) CL-USER(3): (my-recursive-remove 'a '((((a))))) (((nil)))
Problem #5 - Flatten a list  
Write a Common Lisp function called flatten that takes a list that may have embedded lists, and returns a flattened version of it (i.e., a list whose elements are only atoms and empty lists have been removed). Examples of the function in operation (user input is in red):
CL-USER(1): (flatten '(a b c d)) (a b c d) CL-USER(2): (flatten '(a () b (c d))) (a b c d) CL-USER(3): (flatten '(a (()))) (a) CL-USER(4): (flatten '(a (b c) (d e (f) ((((((g)))) h)) i) j (k) l)) (a b c d e f g h i j k l)
somoone help me with LIST.Im temible with this lanpuape It is a good idea to start this assignment early Lisp programming, while not inherently difficut often seem somewhat foreien at fies, particularly when it comes to recunion and ist manipulation, This assignment is loosely based on material by Dr.Hen Casanova Make sure you have extemsive comments! Problem#1 Define a finton that takes two ang ne ts andresnsthe pARIoftheno. Problem #2 Write a fndi e called ides that ㏁upS Intundialetlinthe equalet length n centimeters If x is the fint emene and yin the second, the forma 2 For example 388 33 1 nches 2.5 Problem#3-Remove an element from allir using ltenin of the function in operstion ane shown below (user input is ind CL-USER -renoveba bebd Ll Problen 4-Remeve an elemest frem a list using Reeursion Problem 4-Krmeve an elemeat trem alist uing Recurien wete a Common Lup faction cated mr.recurz; ve-renove t t sin .. สเต any Examplies of the fanction in operation are sow below(user input s a be moved). Examples of the function in operation (user iut is in md CLUSER Elatcenabe

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code that you can try :

1 . (defun greater (a b) (if (> a b) a b))

    (print (greater 6 7))

2. (defun convert-one (inches)
(* inches 2.54))

3. (defun my-remove (lst elem &optional final)
(cond
((and (atom lst) (eql lst elem)) nil)
((listp lst) (mapcan (lambda (e) ( my-remove e elem final)) lst))
(t (nconc final lst))))

4. (defun my-recursive-remove (thing l)
(cond ((null l) '())
((eql thing l) '())
((atom l) l)
((eql (first l) thing) (my-recursive-remove thing (rest l)))
((atom (first l)) (cons (first l)
(my-recursive-remove thing (rest l))))
(t (cons (my-recursive-remove thing (first l))
(my-recursive-remove thing (rest l))))))


5. (defun flatten (lst)
(cond
((null lst) nil)
((atom lst) (list lst))
(t (loop for a in lst appending (flatten a)))))

If any doubts ,comment below ...

Add a comment
Know the answer?
Add Answer to:
Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or...

    Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or LISP if you prefer) . A function (binomial N k) that returns the binomial coefficients C(N, k), defined recursively as: C(NO) = 1, C(N, N) = 1, and, for 0<k < N E(N, k) = C(N-1, k) + C(N-1, k-1) 2. A function (mod N M) that returns the modulus remainder when dividing N by M 3. A function (binaryToDecimal b) that takes a...

  • Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol...

    Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol and a list. Count the number of instances of x in the list. Do not count the number of x in any sub-lists within the list. Test: count-of 'a '(a 'a(a c) d c a). Result: 2 trim-to (symbol list): Write a function named trim-to that takes a symbol and list as parameters. Return a new list starting from the first occurrence of the...

  • 5. Define a LISP function MONTH-INTEGER which takes as argument a symbol that should be the...

    5. Define a LISP function MONTH-INTEGER which takes as argument a symbol that should be the name of a month, and which returns the number of the month. For example, (MONTH-INTEGER MARCH) 3 and (MONTH-INTEGER JUNE) 6. If the argument is not a symbol that is the name of a month, the function should return the symbol ERROR. E.g., (MONTH-INTEGER C) ERROR, (MONTH-INTEGER 7) ERROR ( MONTH-INTEGER 'QUOTE)-> ERROR, and ( MONTH-INTEGER "(MAY))-> ERROR. 6. Define a LISP function SCORE->GRADE...

  • Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns...

    Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns all the items of each list concatenated together into one new 1D list. For example: flatten ([["a", "b"],["c","0"],["e","f"]]) would return ["a", "b","C","d", "e","f"] Save the function in a PyDev library module named functions.py Write a program t03.py that tests flatten function and prints the returned flat list to the screen. Test your program with a different list, hardcoded in t03.py • Copy the results...

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

  • Please Provide me all Necessary Screenshot with copy able code. Thanks Write a scheme function named...

    Please Provide me all Necessary Screenshot with copy able code. Thanks Write a scheme function named up-to-first-number that takes a list as its input and returns a list containing all the elements up to the first numeric element in the input list. You can use the number? predicate function to determine whether an element is a number or not. Sample runs: (up-to-first-number '(a b c d 1 2 3 )) returns (a b c d) (up-to-first-number '(d e f 7))...

  • Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...

    Please place all of the following functions (defun …) into a SINGLE .lsp file As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide ​ Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number. Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers. Do not worry about efficiency here. HINT: You can use ONEFIB...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • C++ Programming please answer both questions and if anyone knows the source of this questions (Book,...

    C++ Programming please answer both questions and if anyone knows the source of this questions (Book, Website, ...) please let me know. thanks A. (10 Points) Recursive Minimum Write a recursive method that computes the minimum element of an array Hint: The minimum value in an array is either the first element, or the minimum number in the rest of the array, whichever is smaller. B. (10 Points) Recursive Count Write a recursive function to count (from 1) up to...

  • PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a l...

    PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a list of albums. The named tuples used for Albums and Songs are defined below, and an example of a music collection is given. (DO NOT HARDCODE THE VALUES FOR MUSIC!) Album = namedtuple('Album', 'id artist title year songs') Song = namedtuple('Song', 'track title length play_count') MUSIC = [ Album("1", "Peter Gabriel", "Up", 2002, [Song(1, "Darkness", 411, 5), Song(2, "Growing Up",...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT