home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / doc / learn / p5 < prev    next >
Encoding:
Text File  |  1979-01-10  |  11.8 KB  |  586 lines

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