Access over 20 million homework & study documents

4 Write a lisp function ask and tell that processes simple sentence

Content type
User Generated
Rating
Showing Page:
1/7
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 youre 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 DONT 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) )
YOUVE CHANGED YOUR MIND ARE YOU SURE?
no
OK
>(ask-and-tell (does mary like hiking) )
YES
>(ask-and-tell (mary hates hiking) )
YOUVE CHANGED YOUR MIND ARE YOU SURE?

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
yes
OK
>(ask-and-tell (does mary like hiking) )
NO
Solution
; -*-mode : lisp ; package : kw-user -*-
(in-package kw-user)
;;; ---------------- OBJECT DEFINITIONS ------------
(def-kb-class node ()
((animal :initform nil :accessor node-likehate
:initarg :likehate )
(question :initform nil :accessor node-question
:initarg :question)
(yes-node :initform nil :accessor node-yes-node
:initarg :yes-node)
(no-node :initform nil :accessor node-no-node
:initarg :no-node)))
(def-kb-class root ()
((node :initform nil :accessor root-node
:initarg :node)))
(def-kb-struct current-node node)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
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 hik ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
I was struggling with this subject, and this helped me a ton!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4