TEACH PROBLEMS1 Aaron Sloman, Oct 97 Revised 2 Nov 1999 Mid-term exercise, to be handed in to Parveen by Friday 12th Nov 5pm. CONTENTS -- Introduction: Choosing your problem -- Submission (See date at top of this page) -- -- Format for the report1 file -- -- Include tests for your procedures -- -- Attach the checklist to your report -- Problem 1: A version of RESPOND -- -- 1.a. family words -- -- 1.b. angels and prime minister -- -- 1.c. more informative -- -- 1.d. repetitions -- -- 1.e. badword -- -- 1.f. ill to better -- -- Further instructions for Problem 1. -- Problem 2: a simple diary manager -- -- 2.a. what_appointment(day, date, time) -> what -- -- 2.b. when_subject(month, subject) -> appointments -- -- Further instructions for problem 2 -- Problem 3: Extending the diary manager -- -- 3.c. duplicates -- -- 3.d. change_appointments(date, num); -- -- 3.e. A diary manager version of "respond" -- -- Further instructions for problem 3 -- Introduction: Choosing your problem -------------------------------- As indicated in the table of contents there are three problems of increasing difficulty. You can choose the one which corresponds to what you think you can do in about a week. Don't actually start working on this before Monday 8th November, as you may need to learn things from other exercises first (e.g. the RIVER2 teach file is useful for exercise 2). Ideally you should not spend more than four or five days on this as otherwise it could interfere too much with your normal learning. -- Submission (See date at top of this page) -------------------------- When you have finished the exercise, put your report, including both the program code and the documentation in a file in your top level directory which should be called 'report1'. Print out a copy of your report using the following command in VED, with "xxx" replaced by the name of the printer in the lab (e.g. lw-g3): ENTER psprint -p -Pxxx e.g. ENTER psprint -p -Plw-g3 (See TEACH * PRINTING): You will find it best to develop the programs in another file, e.g. a file called 'report1.p' since the '.p' suffix gives the editor useful information, e.g. about formatting. When it is all done you can copy your programs, your tests, and your sample output, into the file report1 and then add explanatory text. NB It is easier to type text into a file which does not have '.p' in its name, because then VED will handle automatic line breaks. Clip the checklist sheet (see below) to the printed copy of your report and hand in both checklist and report by the deadline above. -- -- Format for the report1 file The 'report1' file should have a header giving details including where the file is, what it is for, and which problem you have tackled, your name, and the date. Use "ENTER fileheader" to start it off. The whole file should not print out as more than two or three pages at most --- i.e. at most about 180 lines in the file, perhaps a bit more for the longer problem. This exercise is merely intended to help you consolidate your learning, and give us (and you) clues as to any major misconceptions that may need attention. It also gives you practice in describing a program you have written. It is not meant to be an academic hurdle where performance will affect your future. Non-submission may be taken into account in a way that will be determined later. Note that for your mini-project at the end of term a different format will be required (See TEACH * REPORTS) -- -- Include tests for your procedures After all the procedure definitions include (in a multi-line comment using /* ... */) some tests which check that your version of each procedure behaves as described in the specification of the problem (see below for problem specifications). IMMEDIATELY AFTER EACH TEST COMMAND include the output that it actually produces, also within the comment. (I.e. copy it in from the output.p file.) -- -- Attach the checklist to your report Look at TEACH * PROBLEMS1.CHECKLIST This is a document that will be used in checking your report and you will eventually get it back with ticks and perhaps some additional comments. You will be given a printed copy of this. FILL IN the top part of the problems1.checklist sheet and attach it to the FRONT of your report when you hand it in. One of the demonstrators will write comments which will be returned to you after a week or two. Please try to keep a record of the total time it takes you to do your chosen problem, to help guide me in doing this in future. Write the approximate total number of hours on the checklist sheet. It will not be used in any way that affects you. Make sure your name is on EVERY page and pages are numbered and clipped together, to prevent confusion. Deadline and submission information are at the top of this file. If you haven't finished your selected problem by the deadline, just submit a report on whatever you have have completed rather than letting it drag on and hold up your other work. Choose one of the following problems. How long they will take you depends on your knowledge and skill at programming, which will be different for different students. I hope you can do your chosen problem in no more than about four or five days, including testing and writing the description of what you have done. -- Problem 1: A version of RESPOND ------------------------------------ This problem is suitable for people who may have finished TEACH RESPOND, but have not got far with TEACH RIVER2. It uses the pattern matcher, but not the database. For most students this should be too easy. But it may be useful revision. Produce a version of the respond procedure described in TEACH RESPOND with the properties described below: NB Define ONE procedure which handles all these cases, not several different procedures. -- -- 1.a. family words a. If the user types in a sentence containing one or more of the words mother father sister brother then the program responds with [tell me more about your family] -- -- 1.b. angels and prime minister b. If the user types in a sentence that starts with the word "you" and ends with "me" then the program takes the words in between, stores them in a list and prints out a sentence of the form I always suspected angels ... the prime minister with the words in the list replacing the three dots. E.g. YOU ARE TRYING TO FOOL ME could produce I ALWAYS SUSPECTED ANGELS ARE TRYING TO FOOL THE PRIME MINISTER -- -- 1.c. more informative c. If the user types in a sentence with only one or two words, no matter what they are, the program responds with a request to be more informative. -- -- 1.d. repetitions d. If the user types in a sentence containing the same word twice, the program responds [please do not repeat yourself] -- -- 1.e. badword e. Define a procedure called "badword" taking one word as input and a boolean (true or false) as output. If the word is one of "ill", "bad", or "unwell" it should return the result true, otherwise false. Use the Pop-11 procedure member in your definition. See HELP * MEMBER -- -- 1.f. ill to better (This goes beyond TEACH RESPOND) f. If the user types in a sentence containing one of these phrases feel ill feel bad feel unwell the program prints out the same thing except with the word "better" replacing the word after "feel". Do this using a pattern in which the procedure "badword" occurs as a "restriction procedure" in a pattern, e.g. feel ?word:badword (See TEACH PRIMER and search for "restriction", in CHAPTER 7. Or read HELP * MATCHES) -- -- Further instructions for Problem 1. AT THE TOP OF YOUR REPORT1 FILE, in a comment, say what the procedure respond is for, what sorts of inputs it produces, what sorts of outputs it produces and how it produces the output. Your explanation should not take more than 10 lines: i.e. it is a high level explanation not a detailed line by line explanation. AT THE END OF THE FILE add a SHORT comment describing one way in which your procedure respond could be extended. Say (a) what new sort of capability would be provided (b) how it might be implemented in Pop-11 (don't write the code, just mention the techniques to be used). Can you see any ambiguity in the above problem specification regarding priorities of rules? -- Problem 2: a simple diary manager ---------------------------------- If you have already started using database facilities introduced in TEACH * RIVER2 then you can tackle this problem. Define the following procedures which could be part of a diary manager which stores information about your appointments in the format [<weekday> [<month> <day>] <time> <what>] Where: o <weekday> is one of the words "monday" "tuesday", etc. o <month> is one of the three letter words "jan" "feb" "mar" "apr", etc. o <day> is an integer in the range 1 to 31 o <time> is a number e.g. 9, 10, 11, 12, 13 representing the time of day, using the 24 hour clock o <what> is a list describing the appointment in two words, i.e. the first word is one of "philosophy" "linguistics" "psychology" "programming" and the second word is one of "tutorial" "lecture" "lab" E.g. [friday [oct 30] 10 [philosophy tutorial]] [tuesday [nov 3] 12 [programming lecture]] Prepare an initial sample database with at least 10 appointments, two of them on a tuesday, at least four in october and some in november, at various times between 9 and 17 involving various combinations of subject and type of event. Define the following procedures: -- -- 2.a. what_appointment(day, date, time) -> what Given a word (the weekday) a list containing the date (month and day) and a time (integer) this procedure returns false if there is no appointment otherwise it returns the list describing the appointment. -- -- 2.b. when_subject(month, subject) -> appointments Given a month (e.g. "nov"), and a subject, e.g. "philosophy" it returns a list (possibly empty) of the relevant appointments where each item in the list has this format [<weekday> <day of month> <time> <class-type>] e.g. when_subject("nov", "philosophy") => might print out this list [[tuesday 4 10 lab] [thursday 27 12 lecture] ...] Use "foreach" to do this. -- -- Further instructions for problem 2 At the end of the file add a SHORT comment describing one way in which the diary manager could be improved or extended. Say (a) what new sort of capability would be provided (b) how it might be implemented in Pop-11 (don't write the code, just mention the techniques). -- Problem 3: Extending the diary manager ------------------------------ You can try this if you have completed RIVER2 and RIVERCHAT. This is an extended version of Problem 3. Define the procedures in Problem 2, and and IN ADDITION define the following procedures (or as many of them as you have time for). Then write and print a report as described above. -- -- 3.c. duplicates Define a procedure duplicates() -> result which takes no inputs but checks to see whether there are two appointments at the same time on the same day in the database. If there are no duplicates it returns false. If there is a double booking it returns a list of information about the first clashing pair that it finds in this format: [<weekday> [<month> <day>] <time> [<what1> <what2>]] where each of <what1> and <what2> is a list of two items giving the <class-type> information described previously. For example, this result might be used to report a clash: [wednesday [nov 5] 9 [[programming lab] [philosophy lecture]]] -- -- 3.d. change_appointments(date, num); Define a procedure change_appointments(date, num); Finds all the appointments on the specified date (given as a list with month and day) and moves them to a later time on the same date, where the time is increased by num hours. So if num is 3, then an appointment at 9 is moved to 12, one at 11 is moved to 14, etc. How will you test this procedure, since it doesn't print anything out? -- -- 3.e. A diary manager version of "respond" Define a "respond" procedure which takes as input a list of words forming an English sentence and uses the contents of the sentence to invoke one of the procedures described previously in (a), (b) and (c). If you are feeling very ambitious make it deal with task 3.c. so that if you ask it about duplicates it tells you and invites you to decide which item to delete. Equally you can try doing something about case 3.d. -- -- Further instructions for problem 3 YOUR REPORT FILE MUST INCLUDE TESTS which check that your version of each procedure behaves as described above. Include sample tests of your respond procedure, with English sentences. IMMEDIATELY AFTER EACH TEST INCLUDE THE OUTPUT that it produces when you run the test. AT THE END OF THE FILE add a SHORT comment describing one way in which the diary manager could be improved or extended. Say (a) what new sort of capability would be provided (b) how it might be implemented in Pop-11 (don't write the code, just mention the techniques). --- $poplocal/local/teach/problems1 --- Copyright University of Birmingham 1999. All rights reserved. ------