Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

can anyone figure this out !! Pls Help Me

(LISP)

Write functions to perform each of the followings. You are not required to write any documentation for the codes but include a report addressing all the issues mentioned below. Even though SDLC is not required but please include the screen shots for your input and output.

i. For each of the expressions below, write Lisp code that will return that
expression. Your code should use only CONS, NIL, 1, and parentheses; no
other elements of the Lisp language should be used.
a. (1)
b. ((1) 1)
c. (1 1 (1))
d. (1 1)
e. ((1 1) 1)

ii. Write a function takes a list and returns a random element of that list.
iii. Write a function that takes a list and a number and returns a list of the given number of elements. For example,

(function '(I you me) 5)

might return

(you me I I you)

iv. Write a function INFIX-CALC that takes an arithmetic expression in
infix notation and returns the result of the specified calculation. For
example:

(infix-calc '((55 + (20 * 2.1)) / 4)) ==> 24.25

You may assume that all operators take exactly two arguments, that all
atoms in the input are either operators or numbers, and that the expression
is fully parenthesized.
v. Write a program to argue with yourself. Your program should take statements that are typed in as a list and change the pronouns and negate the verbs. For instance, you should change to I, are should change to am not, and so on. Here is a possible sample session:

(argue (you are a stupid computer))
(I am not a stupid computer)
(argue (you are))
(I am not)
(argue are))
(am not)
(argue (I am a smart human))
(you are not a smart human)
(argue (your mother does wear a hat))
(my mother does not wear a hat))
(argue (you are argumentative))
(I am not argumentative)



vii. Write a function, hanoi, that takes a single number as input and prints out the solution to the Towers of Hanoi problem for that many disks. This is the problem of moving a stack of k disks of decreasing size from bottom to top, from the first peg to the third peg with another peg that may be used as well, subject to the condition that a larger disk is never put on top of a smaller one, and only one disk may be moved at a time. (Make sure you understand the problem first). Here is a sample run:

(hanoi 3)

move disk from peg 1 to peg 3
move disk from peg 1 to peg 2
move disk from peg 3 to peg 2
move disk from peg 1 to peg 3
move disk from peg 2 to peg 1
move disk from peg 2 to peg 3
move disk from peg 1 to peg 3
NIL

Write a report based on the points given below. Try to refer to your codes/programs above to support your points/arguments for this part. No documentation is needed for the coding.

i. Discuss the history/origin of LISP language. Highlight how the language has evolved since it was developed.
ii. Assess LISP based on the language evaluation criteria discussed in the lecture. (This is where you can refer to the codes above to support your discussions). You may also include other code snippets, but make you understand them.
iii. Discuss the scoping supported by LISP. Include sample codes to explain/highlight the difference between static and dynamic scoping.
iv. Summarize the pros and cons of using LISP especially in solving the above problems. Try to highlight your points by coding one of the questions above in a different language and make comparisons.


Comments

Sign In or Register to comment.