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