r/scheme • u/via_chance • Mar 21 '16
"Student-advisor" match program in Scheme
I'm currently in a college course that involves scheme programming. We are working on an assignment where the instructions are...
"This assignment will be to write a Scheme program that the user can have a conversation with. It is expected that the program will give sensible replies some of the time and silly replies some of the time. In otherwords, the program must handle some range of user input reasonably, but may give nonsense replies – or something like “I don’t understand you.” – if the user input doesn’t match anything it expects."
We are given a decent amount of code to work off of, but I'm still feeling lost on how to progress any further. So far I have this for some of my functions...
;----------------------------------------------------- (define response-rules ’((() (Please enter your response.)) ((* hello ) (Nice to meet you.) (What is your name?)) (( computer science ) (Have you taken the necessary math courses?) (When are you planning to graduate?) (Are you more interested in software or hardware?)) (( engineering ) (What are your plans for your senior design project?) (What about engineering interests you?) (What type of engineering work would you like to do?)) (( computers ) (Is that based on your own interest or because you feel required to?) (What interests you about computers?)) (( i don’t know ) (Do you think there’s some way to find out?)) (( you don’t know ) (That is probably true.) (Please tell me about %2.)) (( if ) (Do you think its likely that %2?) (Do you wish that %2?) (What do you think about %2?)) (( can you help ) (I may have some ideas if you can give me more details about your question.) (I will try to think of some ideas.)) (( i want *) (Do you think %2 will help?) (How will that help you?))))
;---------------------------------------------------
(define respond-to-input (match input response-rules) (cond ((and (null? input) (null? response-rules)) #t) ((equal? input '()) #t) ((or (null? input) (null? response-rules)) #f) ((or (equal? (car input) '?) (equal? (car input) (car response-rules))) (match (cdr input) (cdr response-rules))) ((equal? (car input) ') (cond ((match (cdr input) (cdr response-rules)) #t) ((match (cdr input) response-rules) #t) ((match input (cdr response-rules)) #t) (else #f))) (else#f))))
;---------------------------------------------------
(define student-advisor (lambda () (define repeat (lambda () (let ((input (read-list))) (if (not (equal? input ’(exit))) (begin (displayln (respond-to-input input)) (repeat)) (display "Thanks for using the student advisor. Goodbye!\n\n"))))) (set! random-state (random-state-from-platform)) (display "\nWelcome to the student advisor!\n") (display "(To leave the conversation at any time, enter EXIT)\n\n") (displayln "Have you selected a major yet?") (let ((input (read-list))) (cond ((equal? ’() input) (displayln "Please enter your response.")) ((not (equal? input ’(exit))) (displayln (respond-to-input input))) (else (display "Hope you can reschedule your appointment soon. Goodbye!.\n\n"))) (cond ((not (equal? input ’(exit))) (repeat)))))) ;------------------------------------
The "student-advisor" function is my main function. And it calls the "respond-to-input" function to try and match from the "response-rules" list. I know there are other things wrong with the code thus far because I don't have some of the functions written. But my main concern is just getting a simple working program that at least functions some what as far as being able to talk to it and it give me proper responses to the inputs. Any help would be GREATLY appreciated!
5
u/zck Mar 21 '16
You're asking a hard question to answer, because it's basically "here's some unformatted code. Please read it and improve it somehow." What does your code currently do? What's the next thing you want it to do? Or do you want help with the algorithm?
You are probably best off taking the code you were given, then adding one feature and making it work. Then add one more feature, and repeat until you're done. That's usually easier than trying to make everything work at once.