Commit | Line | Data |
---|---|---|
ff262511 KB |
1 | .\" %sccs.include.proprietary.roff% |
2 | .\" | |
3 | .\" @(#)p5 6.2 (Berkeley) %G% | |
6d23238a KD |
4 | .\" |
5 | .NH | |
6 | The Script Interpreter. | |
7 | .PP | |
8 | The | |
9 | .I | |
10 | learn | |
11 | .R | |
12 | program itself merely interprets scripts. It provides | |
13 | facilities for the script writer to capture student | |
14 | responses and their effects, and simplifies the job | |
15 | of passing control to and recovering control from the student. | |
16 | This section describes the operation and | |
17 | usage of the driver program, | |
18 | and indicates what is | |
19 | required to produce a new script. | |
20 | Readers only interested in | |
21 | the existing scripts may skip this section. | |
22 | .PP | |
23 | The file structure used by | |
24 | .I learn | |
25 | is shown in Figure 2. | |
26 | There is one parent directory (named \f2lib\f1\^) containing the script data. | |
27 | Within this directory are subdirectories, one for each | |
28 | subject in which a course is available, | |
29 | one for logging (named | |
30 | .I log ), | |
31 | and one in which user sub-directories | |
32 | are created (named | |
33 | .I play ). | |
34 | The subject directory contains master copies of all lessons, | |
35 | plus any supporting material for that subject. | |
36 | In a given subdirectory, | |
37 | each lesson is a single text file. | |
38 | Lessons are usually named systematically; | |
39 | the file that contains lesson | |
40 | .I n | |
41 | is called | |
42 | .I Ln . | |
43 | .br | |
44 | .KF | |
45 | .sp | |
46 | .TS | |
47 | center, box; | |
48 | c s s s | |
49 | l l l l. | |
50 | Figure 2: Directory structure for \fIlearn\fR | |
51 | .sp | |
52 | .nf | |
53 | lib | |
54 | .if t .sp .5 | |
55 | play | |
56 | student1 | |
57 | files for student1... | |
58 | student2 | |
59 | files for student2... | |
60 | .if t .sp .5 | |
61 | files | |
62 | L0.1a lessons for files course | |
63 | L0.1b | |
64 | ... | |
65 | .if t .sp .5 | |
66 | editor | |
67 | ... | |
68 | .if t .sp .5 | |
69 | (other courses) | |
70 | .if t .sp .5 | |
71 | log | |
72 | .TE | |
73 | .sp | |
74 | .KE | |
75 | .PP | |
76 | When | |
77 | .I | |
78 | learn | |
79 | .R | |
80 | is executed, it makes a private directory | |
81 | for the user to work in, | |
82 | within the | |
83 | .I | |
84 | learn | |
85 | .R | |
86 | portion of the file system. | |
87 | A fresh copy of all the files used in each lesson | |
88 | (mostly data for the student to operate upon) is made each | |
89 | time a student starts a lesson, | |
90 | so the script writer may assume that everything | |
91 | is reinitialized each time a lesson is entered. | |
92 | The student directory is deleted after each session; any permanent records | |
93 | must be kept elsewhere. | |
94 | .PP | |
95 | The script writer must provide certain basic items | |
96 | in each | |
97 | lesson: | |
98 | .IP (1) | |
99 | the text of the lesson; | |
100 | .IP (2) | |
101 | the set-up commands to be executed before the user gets control; | |
102 | .IP (3) | |
103 | the data, if any, which the user is supposed to edit, transform, or otherwise | |
104 | process; | |
105 | .IP (4) | |
106 | the evaluating commands to be executed after the user | |
107 | has finished the lesson, to decide whether the answer is right; | |
108 | and | |
109 | .IP (5) | |
110 | a list of possible successor lessons. | |
111 | .LP | |
112 | .I | |
113 | Learn | |
114 | .R | |
115 | tries to minimize the work | |
116 | of bookkeeping and installation, so | |
117 | that most of the effort involved in | |
118 | script production is in planning lessons, | |
119 | writing tutorial paragraphs, | |
120 | and coding tests of student performance. | |
121 | .PP | |
122 | The basic sequence of events is | |
123 | as follows. | |
124 | First, | |
125 | .I learn | |
126 | creates the working directory. | |
127 | Then, for each lesson, | |
128 | .I learn | |
129 | reads the script for the lesson and processes | |
130 | it a line at a time. | |
131 | The lines in the script are: | |
132 | (1) commands to the script interpreter | |
133 | to print something, to create a files, | |
134 | to test something, etc.; | |
135 | (2) text to be printed or put in a file; | |
136 | (3) other lines, which are sent to | |
137 | the shell to be executed. | |
138 | One line in each lesson turns control over | |
139 | to the user; | |
140 | the user can run any | |
141 | .UX | |
142 | commands. | |
143 | The user mode terminates when the user | |
144 | types | |
145 | .I yes , | |
146 | .I no , | |
147 | .I ready , | |
148 | or | |
149 | .I answer . | |
150 | At this point, the user's work is tested; | |
151 | if the lesson is passed, | |
152 | a new lesson is selected, and if not | |
153 | the old one is repeated. | |
154 | .PP | |
155 | Let us illustrate this with the script | |
156 | for the second lesson of Figure 1; | |
157 | this is shown in Figure 3. | |
158 | .KF | |
159 | .sp | |
160 | .TS | |
161 | center, box; | |
162 | c. | |
163 | T{ | |
164 | Figure 3: Sample Lesson | |
165 | .sp | |
166 | .nf | |
167 | ||
168 | Of course, you can print any file with "cat". | |
169 | In particular, it is common to first use | |
170 | "ls" to find the name of a file and then "cat" | |
171 | to print it. Note the difference between | |
172 | "ls", which tells you the name of the files, | |
173 | and "cat", which tells you the contents. | |
174 | One file in the current directory is named for | |
175 | a President. Print the file, then type "ready". | |
176 | #create roosevelt | |
177 | this file is named roosevelt | |
178 | and contains three lines of | |
179 | text. | |
180 | #copyout | |
181 | #user | |
182 | #uncopyout | |
183 | tail \-3 .ocopy >X1 | |
184 | #cmp X1 roosevelt | |
185 | #log | |
186 | #next | |
187 | 3.2b 2 | |
188 | .fi | |
189 | T} | |
190 | .TE | |
191 | .sp | |
192 | .KE | |
193 | .LP | |
194 | Lines which begin with | |
195 | # are commands to the | |
196 | .I learn | |
197 | script interpreter. | |
198 | For example, | |
199 | .LP | |
200 | .ul | |
201 | ||
202 | .LP | |
203 | causes printing of any text that follows, | |
204 | up to the next line that begins with a sharp. | |
205 | .LP | |
206 | .ul | |
207 | #print file | |
208 | .LP | |
209 | prints the contents of | |
210 | .I file ; | |
211 | it | |
212 | is the same as | |
213 | .ul | |
214 | cat file | |
215 | but has | |
216 | less overhead. | |
217 | Both forms of | |
218 | .I #print | |
219 | have the added property that if a lesson is failed, | |
220 | the | |
221 | .ul | |
222 | ||
223 | will not be executed the second time through; | |
224 | this avoids annoying the student by repeating the preamble | |
225 | to a lesson. | |
226 | .LP | |
227 | .ul | |
228 | #create filename | |
229 | .LP | |
230 | creates a file of the specified name, | |
231 | and copies any subsequent text up to a | |
232 | # to the file. | |
233 | This is used for creating and initializing working files | |
234 | and reference data for the lessons. | |
235 | .LP | |
236 | .ul | |
237 | #user | |
238 | .LP | |
239 | gives control to the student; | |
240 | each line he or she types is passed to the shell | |
241 | for execution. | |
242 | The | |
243 | .I #user | |
244 | mode | |
245 | is terminated when the student types one of | |
246 | .I yes , | |
247 | .I no , | |
248 | .I ready | |
249 | or | |
250 | .I answer . | |
251 | At that time, the driver | |
252 | resumes interpretation of the script. | |
253 | .LP | |
254 | .ul | |
255 | #copyin | |
256 | .br | |
257 | .ul | |
258 | #uncopyin | |
259 | .LP | |
260 | Anything the student types between these | |
261 | commands is copied onto a file | |
262 | called | |
263 | .ul | |
264 | \&.copy. | |
265 | This lets the script writer interrogate the student's | |
266 | responses upon regaining control. | |
267 | .LP | |
268 | .ul | |
269 | #copyout | |
270 | .br | |
271 | .ul | |
272 | #uncopyout | |
273 | .LP | |
274 | Between these commands, any material typed at the student | |
275 | by any program | |
276 | is copied to the file | |
277 | .ul | |
278 | \&.ocopy. | |
279 | This lets the script writer interrogate the | |
280 | effect of what the student typed, | |
281 | which true believers in the performance theory of learning | |
282 | usually | |
283 | prefer to the student's actual input. | |
284 | .LP | |
285 | .ul | |
286 | #pipe | |
287 | .br | |
288 | .ul | |
289 | #unpipe | |
290 | .LP | |
291 | Normally the student input and the script commands | |
292 | are fed to the | |
293 | .UX | |
294 | command interpreter (the ``shell'') one line at a time. This won't do | |
295 | if, for example, a sequence of editor commands | |
296 | is provided, | |
297 | since the input to the editor must be handed to the editor, | |
298 | not to the shell. | |
299 | Accordingly, the material between | |
300 | .ul | |
301 | #pipe | |
302 | and | |
303 | .ul | |
304 | #unpipe | |
305 | commands | |
306 | is fed | |
307 | continuously through a pipe so that such sequences | |
308 | work. | |
309 | If | |
310 | .ul | |
311 | copyout | |
312 | is also desired | |
313 | the | |
314 | .ul | |
315 | copyout | |
316 | brackets must include | |
317 | the | |
318 | .ul | |
319 | pipe | |
320 | brackets. | |
321 | .PP | |
322 | There are several commands for setting status | |
323 | after the student has attempted the lesson. | |
324 | .LP | |
325 | .ul | |
326 | #cmp file1 file2 | |
327 | .LP | |
328 | is an in-line implementation of | |
329 | .I cmp , | |
330 | which compares two files for identity. | |
331 | .LP | |
332 | .ul | |
333 | #match stuff | |
334 | .LP | |
335 | The last line of the student's input | |
336 | is compared to | |
337 | .I stuff , | |
338 | and the success or fail status is set | |
339 | according to it. | |
340 | Extraneous things like the word | |
341 | .I answer | |
342 | are stripped before the comparison is made. | |
343 | There may be several | |
344 | .I #match | |
345 | lines; | |
346 | this provides a convenient mechanism for handling multiple | |
347 | ``right'' answers. | |
348 | Any text up to a | |
349 | # on subsequent lines after a successful | |
350 | .I #match | |
351 | is printed; | |
352 | this is illustrated in Figure 4, another sample lesson. | |
353 | .br | |
354 | .KF | |
355 | .sp | |
356 | .TS | |
357 | center, box; | |
358 | c. | |
359 | T{ | |
360 | Figure 4: Another Sample Lesson | |
361 | .sp | |
362 | .nf | |
363 | ||
364 | What command will move the current line | |
365 | to the end of the file? Type | |
366 | "answer COMMAND", where COMMAND is the command. | |
367 | #copyin | |
368 | #user | |
369 | #uncopyin | |
370 | #match m$ | |
371 | #match .m$ | |
372 | "m$" is easier. | |
373 | #log | |
374 | #next | |
375 | 63.1d 10 | |
376 | T} | |
377 | .TE | |
378 | .sp | |
379 | .KE | |
380 | .LP | |
381 | .ul | |
382 | #bad stuff | |
383 | .LP | |
384 | This is similar to | |
385 | .I #match , | |
386 | except that it corresponds to specific failure answers; | |
387 | this can be used to produce hints for particular wrong answers | |
388 | that have been anticipated by the script writer. | |
389 | .LP | |
390 | .ul | |
391 | #succeed | |
392 | .br | |
393 | .ul | |
394 | #fail | |
395 | .LP | |
396 | print a message | |
397 | upon success or failure | |
398 | (as determined by some previous mechanism). | |
399 | .PP | |
400 | When the student types | |
401 | one of the ``commands'' | |
402 | .I yes , | |
403 | .I no , | |
404 | .I ready , | |
405 | or | |
406 | .I answer , | |
407 | the driver terminates the | |
408 | .I #user | |
409 | command, | |
410 | and evaluation of the student's work can begin. | |
411 | This can be done either by | |
412 | the built-in commands above, such as | |
413 | .I #match | |
414 | and | |
415 | .I #cmp , | |
416 | or by status returned by normal | |
417 | .UX | |
418 | commands, typically | |
419 | .I grep | |
420 | and | |
421 | .I test . | |
422 | The last command | |
423 | should return status true | |
424 | (0) if the task was done successfully and | |
425 | false (non-zero) otherwise; | |
426 | this status return tells the driver | |
427 | whether or not the student | |
428 | has successfully passed the lesson. | |
429 | .PP | |
430 | Performance can be logged: | |
431 | .LP | |
432 | .ul | |
433 | #log file | |
434 | .LP | |
435 | writes the date, lesson, user name and speed rating, and | |
436 | a success/failure indication on | |
437 | .ul | |
438 | file. | |
439 | The command | |
440 | .LP | |
441 | .ul | |
442 | #log | |
443 | .LP | |
444 | by itself writes the logging information | |
445 | in the logging directory | |
446 | within the | |
447 | .I learn | |
448 | hierarchy, | |
449 | and is the normal form. | |
450 | .LP | |
451 | .ul | |
452 | #next | |
453 | .LP | |
454 | is followed by a few lines, each with a successor | |
455 | lesson name and an optional speed rating on it. | |
456 | A typical set might read | |
457 | .LP | |
458 | .nf | |
459 | 25.1a 10 | |
460 | 25.2a 5 | |
461 | 25.3a 2 | |
462 | .fi | |
463 | .LP | |
464 | indicating that unit 25.1a is a suitable follow-on lesson | |
465 | for students with | |
466 | a speed rating of 10 units, | |
467 | 25.2a for student with speed near 5, | |
468 | and 25.3a for speed near 2. | |
469 | Speed ratings are maintained for | |
470 | each session with a student; the | |
471 | rating is increased by one each time | |
472 | the student gets a lesson right and decreased | |
473 | by four each | |
474 | time the student gets a lesson wrong. | |
475 | Thus the driver tries to maintain a level such | |
476 | that the users get 80% right answers. | |
477 | The maximum rating is limited to 10 and the minimum to 0. | |
478 | The initial rating is zero unless the student | |
479 | specifies a different rating when starting | |
480 | a session. | |
481 | .PP | |
482 | If the student passes a lesson, | |
483 | a new lesson is selected and the process repeats. | |
484 | If the student fails, a false status is returned | |
485 | and the program | |
486 | reverts to the previous lesson and tries | |
487 | another alternative. | |
488 | If it can not find another alternative, it skips forward | |
489 | a lesson. | |
490 | .I bye , | |
491 | bye, | |
492 | which causes a graceful exit | |
493 | from the | |
494 | .ul | |
495 | learn | |
496 | system. Hanging up is the usual novice's way out. | |
497 | .PP | |
498 | The lessons may form an arbitrary directed graph, | |
499 | although the present program imposes a limitation on cycles in that | |
500 | it will not present a lesson twice in the | |
501 | same session. | |
502 | If the student is unable to answer one of the exercises | |
503 | correctly, the driver searches for a previous lesson | |
504 | with a set of alternatives as successors | |
505 | (following the | |
506 | .I #next | |
507 | line). | |
508 | From the previous lesson with alternatives one route was taken | |
509 | earlier; the program simply tries a different one. | |
510 | .PP | |
511 | It is perfectly possible | |
512 | to write sophisticated scripts that evaluate | |
513 | the student's speed of response, or try to estimate the | |
514 | elegance of the answer, or provide detailed | |
515 | analysis of wrong answers. | |
516 | Lesson writing is so tedious already, however, that most | |
517 | of these abilities are likely to go unused. | |
518 | .PP | |
519 | The driver program depends heavily on features | |
520 | of | |
521 | .UX | |
522 | that are not available on many other operating systems. | |
523 | These include | |
524 | the ease of manipulating files and directories, | |
525 | file redirection, | |
526 | the ability to use the command interpreter | |
527 | as just another program (even in a pipeline), | |
528 | command status testing and branching, | |
529 | the ability to catch signals like interrupts, | |
530 | and of course | |
531 | the pipeline mechanism itself. | |
532 | Although some parts of | |
533 | .ul | |
534 | learn | |
535 | might be transferable to other systems, | |
536 | some generality will probably be lost. | |
537 | .PP | |
538 | A bit of history: | |
539 | The first version of | |
540 | .I learn | |
541 | had fewer built-in words | |
542 | in the driver program, | |
543 | and made more use of the | |
544 | facilities of | |
545 | .UX . | |
546 | For example, | |
547 | file comparison was done by creating a | |
548 | .I cmp | |
549 | process, | |
550 | rather than comparing the two files within | |
551 | .I learn . | |
552 | Lessons were not stored as text files, | |
553 | but as archives. | |
554 | There was no concept of the in-line document; | |
555 | even | |
556 | .I #print | |
557 | had to be followed by a file name. | |
558 | Thus the initialization for each lesson | |
559 | was to extract the archive into the working directory | |
560 | (typically 4-8 files), | |
561 | then | |
562 | .I #print | |
563 | the lesson text. | |
564 | .PP | |
565 | The combination of such things made | |
566 | .I learn | |
567 | slower. | |
568 | The new version is about 4 or 5 times faster. | |
569 | Furthermore, it appears even faster to the user | |
570 | because in a typical lesson, | |
571 | the printing of the message comes first, | |
572 | and file setup with | |
573 | .I #create | |
574 | can be overlapped with the printng, | |
575 | so that when the program | |
576 | finishes printing, | |
577 | it is really ready for the user | |
578 | to type at it. | |
579 | .PP | |
580 | It is also a great advantage to the script maintainer | |
581 | that lessons are now just ordinary text files. | |
582 | They can be edited without any difficulty, | |
583 | and | |
584 | .UX | |
585 | text manipulation tools can be applied | |
586 | to them. | |
587 | The result has been that | |
588 | there is much less resistance | |
589 | to going in and fixing substandard lessons. |