Question: ;;; starter code ;;; We'll use the random function implemented in Racket ;;; (random k) returns a random integer in the range 0 to k-1

;;; starter code

;;; We'll use the random function implemented in Racket ;;; (random k) returns a random integer in the range 0 to k-1 (#%require (only racket/base random))

;;; some input and output helper functions

;;; prompt: prompt the user for input ;;; return the input as a list of symbols (define (prompt) (newline) (display "talk to me >>>") (read-line))

;;; read-line: read the user input till the eof character ;;; return the input as a list of symbols (define (read-line) (let ((next (read))) (if (eof-object? next) '() (cons next (read-line)))))

;;; output: take a list such as '(how are you?) and display it (define (output lst) (newline) (display (to-string lst)) (newline))

;;; to-string: convert a list such as '(how are you?) ;;; to the string "how are you?" (define (to-string lst) (cond ((null? lst) "") ((eq? (length lst) 1) (symbol->string (car lst))) (else (string-append (symbol->string (car lst)) " " (to-string (cdr lst))))))

;;; main function ;;; usage: (chat-with 'your-name)

(define (chat-with name) (output (list 'hi name)) (chat-loop name))

;;; chat loop (define (chat-loop name) (let ((input (prompt))) ; get the user input (if (eqv? (car input) 'bye) (begin (output (list 'bye name)) (output (list 'have 'a 'great 'day!))) (begin (reply input name) (chat-loop name)))))

;;; your task is to fill in the code for the reply function ;;; to implement rules 1 through 11 with the required priority ;;; each non-trivial rule must be implemented in a separate function ;;; define any helper functions you need below (define (reply input name) (output (pick-random generic-response))) ; rule 11 has been implemented for you

;;; pick one random element from the list choices (define (pick-random choices) (list-ref choices (random (length choices))))

;;; generic responses for rule 11 (define generic-response '((that\'s nice) (good to know) (can you elaborate on that?)))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!