LIBRARY OF THE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAICN 510.84 IAQ,y ho. 643-648 cop. 2 The person charging this material is re- sponsible for its return to the library from which it was withdrawn on or before the Latest Date stamped below. Theft, mutilation, and underlining of books are reasons for disciplinary action and may result in dismissal from the University. UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIGN J ti- ll L161 — O-1096 Digitized by the Internet Archive in 2013 http://archive.org/details/pl2daprogramming647lant UIUCDCS-R-7^-647 //{juCk. conditio^ condition^ esac Table 1 Bachnaus-naur Description of Expressions in pl/2d | | [(x 1 -0 ] [( + 1 -) ] ( ) r 'r ( ). [-] [-] abs ( r )^ \ sin ( r ) r | cos ( r ) r | sqrt ( r ) r {} [. {}] 0|l|2|3|^|5|6|7|8 $ and $ | $ or $ l l - 1 / s t[u|v|w|x|y|z note: ( and ) are real parentheses ( and ) are meta-parentheses 10 The case statement is delisted by the keyword 'case' at the beginning and by the keyword 'esac' at the end. The syntax is similar to the IISP cond statement on which pl/2d is based [2]. A condition is defined by a logical expression. In the implementation of pl/2d, a true value is associated with -1 and a false value with 0. The arithmetic value of -1 is also accepted as an unconditional choice that will always be chosen if reached. B. The Editor/Compiler and Interpreter The editor and compiler of pl/2d are really one program. As soon as the student inputs a command it is compiled and stored if correct. At any step of writing the program, the student is assured that all previous lines are meaningful. Since pl/2d was implemented on an interactive system it was feasible to implement the compilation this way. Immediate feedback for the student reinforces learning the correct syntax of the language. Pl/2d recognizes every syntax error and responds with an appropriate message. The student must fix the error or delete the statement to precede. Besides any editing features programmed, the PIATO terminal has many built-in functions that help the student correct a line quickly and easily. Also, at any time, a small review of the editing commands and the pl/2d language is available to the student. Hopefully, the error message and this reference materials will be enough information for the student to correct her/his errors. The editor allows a student to write and edit a program. The editing commands are recognized as keywords like pl/2d. Then, if necessary, a statement number and number of statements to be changed follow the keyword. The commands are described in Table 2. There is a maximum of 25 lines accepted as the total length of the program. 11 T le 2 insert n start inserting after line n replace n start replacing statements with line n delete n, m delete m statements, starting at line n destory destroy the entire program run execute the program The functions of inserting and replacing will be continued until the length of the program exceeds this limit or a blank line is accepted by the editor. A blank line shifts the editor back into normal mode, which allows adding statements to the end of the program. The program is only compiled up to the point where the student is editing. Thus if a student decides to delete line 3 of a 12 -line program, the program will only be compiled up to line 3 before the deletion and the rest of the program must be recompiled after the deletion. The recompilation of the program constantly makes sure that the student understands where her/his errors are in the program. When the student elects to execute his program, control is passed to the interpreter. If the student has defined any parameters in the program definition, the interpreter now asks for initial values. The student is also queried if (s)he would like a trace of the program. The trace is an arrow that points to the statement executing at the moment. Recursion is implemented using a stack. Any call to the program results in all the values being saved as well as the return address. The only execution error that may occur is if the stack overflows. At that 12 time execution is halted, and the student is asked to re-edit her/his program. If asked for, a small explanation of what happened is given. One point to consider is that often a graphical command will reference some place off the screen. This is reasonable sometimes for drawing arcs only partially on the screen since it is impossible to guess exactly which degree will take the arc off the screen. But if the program completely misses the screen, it is obviously not correct. These two situations are both transparent to the simulator. Pl/2d is simulated by TUTOR commands; and these commands will generate points off the screen and light them, even if only on an imaginary extension of the defined matrix. To partially remedy this, a student can always prematurely stop the execution of her/his program. No execution time diagnostics are given for this condition, however. It is assumed that the student is intelligent enough to stop execution. 1. Data Structure A conventional approach has been taken in compiling the language. Most of the time a student spends programming in pl/2d will be spent editing a program. Thus the intermediate code is kept as close to the original as possible. A fixed length of memory is defined for each command. The command is translated into a token number and the length of each parameter is stored. The parameters themselves are stored in strings and not as compiled code. Each time a pl/2d command is executed, the parameters of that command are compiled. This approach was chosen because only a small fraction of the time spent on one program will be during execution. However, this might not have been wise because of the number of recursions and the large number of parameters used in some patterns. Execution might be slower 13 even though the parameters are compiled relatively quick by a specail TUTOR command. The PLATO IV system has 60-bit words and 6-bit characters. Each statement in pl/2d was stored in a 6-variable data structure. A fixed length was chosen because it is easily accessed and saves time instead of searching for a variable length command. It was necessary to use a fixed length to accommodate a maximum length program. Figure 1 is an example of the data structure used to compile a statement in pl/2d. 2. Problems Two problems occurred in implementing pl/2d. First, the compiler could not recognize the difference between the name of a program and either the variables or keywords used in that program. The solution chosen partially solves the problem. All program names must be greater than 1 character in length. However, the compiler does not recognize when a program name is identical to a keyword. The choice of keyword is always matched first. Thus, the student is warned that program names should not be identical to keywords. Another problem of a pl/2d program is slow execution; more complex arguments and larger amounts of recursion visibly slows execution. t The amount of memory allocated to a PLATO program is a non- executable function. Although the trend of PIATO IV programming leans toward lessons that more CPU utilization, the time allotted each terminal per time slice by the system is decreasing. As the lesson is visibly slower, the student might lose interest. The needs of the programs being written demand that the design of computer-assisted instructional system, and PIATO IV in particular, must change. Educational uses of computers do not necessarily imply minimal demands being placed on the system. -p OO hO o 3A £ o CU 3 CO CD o ft P , £ O 0) rH H bO S p CU £ d cu © ^ p o a p p w p •rl 15 C. The Lesson Besides presenting the syntax of the language, the lesson demonstrates some simple examples for the student. Both code and the execution of the programs are presented for each new statement that is presented to the student . As an example, after the graphing and program definition statements are introduced, the student is presented with a program that draws the pattern shown in Figure 2. Figure 2. Pattern Drawn "by Program Emblem From this example the student is introduced to the use of parameters in the program definition and how, by changing the values of these parameters, the design can be drawn in different positions on the screen or even be programmed to change size. The student is first shown a program with fixed arguments (Example l). Gradually the student is guided through intermediate steps until the final version of the program that changes position and size is presented (Example 2) A second example introduces the case statement. The student is asked to choose a starting value between 1 and 3 for a program. The outcome from her/his choice is a face with either a smile, frown, or surprised expression. 16 program emblem 1 draw 400, 350, >+50, 350, U50, 400 draw ^50, 400, 400, 400, 400, 350 circle 25, te5, 375 draw 410, 360, W), 360, 425, 390, UlO, 360 end Example 1. Program Emblem 1 program emblem 3 s, t, u draw s, t, s+u, t, s+u, t+u draw s+u, t+u, s, t+u, s, t circle u+2, s+u+2, t+u+2 draw s+u+5, t+u+5, s-u+5+u, t+u+5, s+u+2, t-u+5+u draw s+u+2, t-u+5+u, s+u-5, t+u-s-5 end Example 2. Final program of emblem which changes position and size. (line 5 of Example 1 has been expanded to 2 statements because the editor only allows 50 characters, including spaces, per line. ) 17 The student can execute this program any number of times before s(he) sees the actual code. The program use statement is demonstrated at first with an iterative program. A sunburst is drawn for the student while the program's execution is traced on the screen. Iterative programming is probably the first serious attempt the student will try on her/his own. The lesson stresses the point that the case statement must be used. With the program statement the program will never stop until the stack overflows. A correct (Example 3) as well as an incorrect (Example k) version of the program is presented. After a gradual introduction to programs in pl/2d, a recursive example is given. The program called 'tri* draws three triangles in every other triangle until the inside triangles have a base less than 10 dots wide. The final result of the program is pictured in Figure 3. Figure 3. Final Output of Recursive Program Tri 18 program sunburst s draw 256, 256, 50 x sin(s) + 256, 50 x cos(s) + 256 sunburst s+10 end Example 3. Incorrect example of iterative program program sunburst s draw 256, 256, 50 x sin(s) + 256, 50 x cos(s) + 256 case s < 36O sunburst s+10 esac end Example k- Correct example of iterative program case statement provides for end of execution 19 The student sees the order the program is executed by watching a trace; (Example 5) and the graphical output also reflects the program recursive behavior. program tri s, t, u draw s, t, s+u-^2, t+u, s, t f — case u > 50 tri s+u-^7, t+u-rlO, u+3 tri s+If*u^7, t+u-s-10, u+3 tri s+u-s-3, t+u*2, u*3 esac end Example 5. Example of recursive program. An arrow traces the statement execution. The entire presentation of the language up to this point should take less than one-half hour. The student is now able to experiment by programming her/his own recursive programs. A suggestion is made to the student of an interesting pattern that might be programmed; then the student enters the editor. 20 IV. CONCLUSION Three points are important to remember. First, within one hour of instruction a student can have an effective tool for experimentation with recursive programming. The language is simple and yet meets all the requirements for generating clear examples. The generation of the output gives some feeling for what recursion is; the instructor has a viable mechanism for presentation. Secondly, the entire lesson is versatile for use by the student. S(he) can read the textual material, write programs, review more material or watch programmed examples in any order that s(he) wishes. The index suggests to the student the order preferred, but anything can be accessed by the student when s(he) wishes. Lastly, the language is designed merely to accommodate recursive programming. The language is brief; the functions of controlling recursion through the program use statement and case statement are stressed. Through experimentation, students can discover that certain types of patterns can only be drawn recursively. A computer-assisted instruction system with a flexible graphics terminal is a viable method for teaching introductory computer science topics. Recursion can be isolated from other topics; and its lesson can be presented at the student's own pace. By eliminating irrelevant material, such as iterative programming techniques, the impact of recursion will have a better lasting effect. Later, the instructor can transfer the 21 technique learned in pl/2d to other programming languages and still maintain continuity because the examples have a similar frame of reference: they are both programming languages. 22 LIST OF REFERENCES [1] Alpert, D. and D. L. Bitzer, "Advances in Computer Based Education," Science , Vol. 167 (20 March 1970), pp. 1582-1590. [2] LISP 1.5 Programmer's Manual , McCarthy, John, Second Edition, Cambridge, Mass., MIT Press, 1966. 5IBLI0GRAPHIC DATA ,HEET 1. Report No. UIUCDCS-R-7^-6^7 3. Recipient's Accession N< Title .ind Suht it It- 5. Report Date pl/2d: A Programming Language for Generating 2 -Dimensional Patterns May 1974 . Author(s) Karen Sebela Lantz 8- Performing Organization Rent. No. Performing Organization Name and Address Department of Computer Science University of Illinois Urbana, Illinois 10. Project/Task/Work Unit No. 11. Contract/Grant No. Sloan AP FDN 2. Sponsoring Organization Name and Address Alfred P. Sloan Foundation 630 Fifth Avenue New York, New York 10020 13. Type of Report & Period Covered 14. 5. Supplementary Notes 6. Abstracts pl/2d is a recursive mini-language which produces a graphical output. The languages allow the student to "see" how recursion works. The motivation for the design was to produce a useful tool that is easy to use and isolates the topic of recursion. 7. Key Words and Document Analysis. 17a. Descriptors 7b. Identifiers/Open-Ended Terms ! 7c. COSATI Tie Id/Group '8. Availability Statement 19. Security C lass (This Report) UNCLASSIFIED 20. Security Class (This Page UNCLASSIFIED 21. No. of Pages 22. Price ORM NTIS-35 (10-70) USCOMM-DC 40329-P1 % A ^ m CO 4b.