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