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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started