This project is worth 2% of your final grade. You will turn in a paper with the
ID: 3770129 • Letter: T
Question
This project is worth 2% of your final grade. You will turn in a paper with the following:
Cover page with your name, id, class, and semester
Each of the four exercises
Snapshots of your input
Snapshots of the output
Any other supporting comments
First, you are to familiarize yourself with the basic common lisp environment and write some simple functions.
Download a common lisp from the internet.
Install the common lisp that you downloaded
Start it and play around with it
Type in some symbols and numbers (‘ a, 5, 3.183, nil, T, “hello”, etc.) and see what results
you get.
Call some basic functions (+ 5 3), (setf a 6), (setf b 12), (* a b), (set c(/ a b)), etc.
Write some simple functions like square, cube, etc.
Write a few list functions like determining if all elements of a list are numbers,
characters, etc.
Start a dribble session. Your first command should be (print “name”) with your name in quotes.
Create a list that stores the courses that you are taking this semester where the courses are stored in sublists as (subjectnumber) such as (CSCI 755) so that your list will look like this: ((CSCI 755) (EENG 641) (ACCT 801) (CHEM 601) (ENGY 720)) and then create 3 other lists for fictitious CSCI and/or EENG majors. All students should have at least one CSCI class. They should all have at least 2 courses, no more than 7
Write the following functions
Given a subject, print all courses of that subject
Print all upper level courses (7xx and 8xx courses)
Count the number of courses that are either CSCI or EENG and return that number
Given a course list, determine whether a given schedule is “hard”, “easy” or
“inbetween”. Where a “hard” schedule is one where the student is taking only upper level courses or only CSCI/EENG courses; an “easy” schedule is one where the student is taking only lower level courses or is one with no CSCI/EENG courses; and “inbetween” is everything else.
4. Write a lisp function ask-and-tell that processes simple sentences. It should allow you to enter lists that represent assertions, such as (Mary likes hiking) or (Steve hates pretzels), as well as questions such as (Does Mary like hiking) or (Does Steve like pretzels). The assertions should all have a proper name (e.g., Mary) in the first position, the word likes or hates in the second position, and either an activity (e.g., hiking) or and object (e.g., pretzels) in the last position. The questions should be similar, except that they begin with the word Does. The function should remember the assertions you give it, and answer your questions appropriately. If you repeat an assertion, it should let you know that; if you enter a contradictory assertion, it should alert you to that, and confirm that you’re sure before making the change. E.g.,
> (ask-and-tell ‘(mary likes hiking) ) “OK”
>(ask-and-tell ‘(steve hates pretzels) ) “OK”
>(ask-and-tell ‘(does mary like hiking) ) “YES”
>(ask-and-tell ‘(does mary like pretzels) ) “I DON’T KNOW”
>(ask-and-tell ‘(mary likes hiking) )
“I KNOW THAT ALREADY” >(ask-and-tell ‘(does steve like pretzels) ) “NO”
>(ask-and-tell ‘(mary hates hiking) )
“YOU’VE CHANGED YOUR MIND ... ARE YOU SURE?”
no
“OK”
>(ask-and-tell ‘(does mary like hiking) )
“YES”
>(ask-and-tell ‘(mary hates hiking) )
“YOU’VE CHANGED YOUR MIND ... ARE YOU SURE?” yes
“OK”
>(ask-and-tell ‘(does mary like hiking) )
“NO”
Explanation / Answer
While Calling some basic functions (+ 5 3), (setf a 6), (setf b 12), (* a b), (set c(/ a b)), etc we will have the output as we expect.
Here we have used the several library defined function like setf which sets the value to the variable.
Moreover we should understand that the LISP uses the prefix notation,which means the operators would be in the front after that the
variable on which the particular operation have to be performed.
For e.g (+5 3) will result in output 8 because it is the prefix of (5+3).
(setf a 6) will set the value of a to 6.
SImilarly the (setf b 12) will set the value of b to 12.
This will multiply the value of A and B, which wil result in 72.
That is how all the operations are performed in LISP.
A)
(defun cube (num list)
(if (zerop num)
list
(cubes (1- num) (cons (* num num num) list))))
This function calculates the cube of the number,when called by the function.
B)
(defun square(x)
(* x x)
This will normally compute the square of the number when called via prompt.
C)
To check whether all the number in the list are numbers or the character we use "every" in this case.
For example I have listed one example below:-
(every 'integerp '(1 2 3 4))
To check for the character we have the floowing functions:-
(loop for z in '(a b c d)
if (not (characterp z)) return nil
else collect (z))
This wil return true if all the element in the list Z are character.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.