DRLOGO.WS4 ---------- - "Digital Research's Dr. Logo" Gary Kildall & David Thornburg "BYTE", June 1983, p.208 (Retyped by Emmanuel ROCHE.) Logo for personal computers has been heralded by some as the beginning of a revolution in computer languages that promises to be as far reaching as the introduction of the personal computer itself. Yet, many people think that Logo is not much more than a graphics language for children. Adding to this confusion is the fact that some commercial implementations of Logo are weak (somewhat akin to a version of English that contained no adjectives). Because of the confusion surrounding Logo itself, the appearance of a sophisticated version of this language on a professional microcomputer such as the IBM Personal Computer might be expected to raise some eyebrows. The development of a powerful Logo for 16-bit computers such as the IBM PC can change our way of thinking about programming. In this article, we will show what makes Logo truly powerful, what it can be used for, and how Digital Research's Dr. Logo, with its powerful language, large workspace, and complete program-development environment, sets a new benchmark by which to measure the properties of useful computer languages. To help you understand the power of Logo, we will give you some background about the earlier language LISP. LISP, developed more than 20 years ago by John McCarthy, is overwhelmingly the language of choice for researchers in the field of artificial intelligence. Unlike many other languages, LISP lets users perform operations on several data types, including numbers, words, and lists. A list can consist of a collection of words, numbers, or lists themselves. Because the names of LISP primitives or procedures are also words, one can write LISP programs that automatically generate other LISP programs. It is the ability to manipulate this type of data that gives LISP its name (LISt Processing). LISP has been used to explore topics as diverse as image processing, the analysis of natural language, the computer solution of certain types of "intelligence" tests, and theorem proving. More mundane programs in LISP (such as word processors) have also been created. Viewed from any angle, it is a powerhouse of a language. Dr. Logo incorporates the list-processing capabilities of LISP with a syntax that can be learned by children. More than the utility (and beauty and simplicity) of turtle graphics, it is this list-processing capacity that gives it so much power. Other important characteristics are shared by Logo and LISP. Among these is the ability to extend the language through the creation of procedures that are treated just as if they were part of the language itself. As with some FORTH devotees, many Logo enthusiasts see themselves as not writing programs, but as creating new "words" in Logo tailored to the solution of their particular programming task. While this may appear to be a subtle distinction, it has a tremendous effect on programming style. This style affected the design of Digital Research's Dr. Logo in several ways, especially in the debugging and procedure-management tools. The power of Dr. Logo --------------------- Before showing what Logo procedures look like, we will list a few of the characteristics of Dr. Logo. To provide maximum power to the user, we designed the first implementation of Dr. Logo for the 16-bit IBM Personal Computer. The use of a 16-bit processor greatly increased the amount of workspace available to the user, and also yielded a modest speed improvement over 8-bit versions of the language. A Dr. Logo user with 192K bytes of RAM has about 10,000 nodes available for use. For comparison, an Apple II user running Apple Logo has only about 2800 free nodes to work with. It goes without saying that sophisticated applications require comparably more workspace than simple ones, and it was important to its designers that Dr. Logo be able to handle sophisticated applications. In addition to list processing and turtle graphics primitives, Dr. Logo can work with integers (30-bits long, plus a sign) and both single-precision and double-precision floating-point numbers. A full set of transcendental functions (log, square root, etc.) allows this language to be used for scientific programs as well. Dr. Logo is a superset of Apple Logo and more than just a language. A complete programming environment, it includes its own operating system, program editor, debugger, and a set of workspace-management tools designed to speed the successful implementation of even the most convoluted artificial-intelligence program. The graphics system is designed to use either the color monitor alone, or to use the color monitor for turtle graphics or mixed text/graphics applications and the monochrome monitor for procedure editing, debugging, and pure text programs. The color display uses the 320- by 200-pixel medium-resolution mode, and supports 16 background colors (8 colors that are either bright or dim). It also supports 2 foreground color sets of 4 colors each. A brief glimpse at Logo procedures ---------------------------------- Before describing the editor and workspace-management tools, we will examine what a Logo procedure looks like by illustrating the creation and manipulation of a list. A list in Logo is a collection of words, numbers, or lists that are enclosed in square brackets ("[" and "]"). Each item in the list is separated by a space. For example, [cow horse sheep snake] is a list; so is [1 1 2 3 5 8]. The first list consists of the words cow, horse, sheep, and snake; the second list consists of the first 6 numbers of the Fibonacci series. A more complex list would be [car [dump truck] airplane [railroad engine]], in which 2 of the elements are words (car and airplane) and 2 elements are lists of 2 words each ([dump truck] and [railroad engine]). Also, a list can have one word in it ([yellow]) or even be empty ([]). In common with other computer languages, Logo allows values to be assigned to names. For example, you can assign a list to a name with the MAKE command, e.g.: make "friends [Pam Roy Pat George] The quotation mark (") is used by Logo to indicate that FRIENDS is a word (a variable name in this case) and not a command. If we tell Logo to print :friends we will see Pam Roy Pat George on the screen. The colon (:) in front of FRIENDS lets Logo know that we want to see what is bound to the variable, rather than the variable name itself. If we had entered print "friends we would have seen friends on the screen instead. You can take lists apart in Logo with commands such as FIRST, BUTFIRST, LAST, and BUTLAST. For example, if we enter print first :friends the screen will show Pam The command print butfirst :friends prints Roy Pat George Now that we know a little about lists, let us explore Logo's extensibility by creating a new command in the language. Suppose you did a lot of work with lists and you found that you would like to rotate a list by moving its first element to the rear end and pushing everything else up front. We can create a word (e.g., rotate) to do this for us. If we had such a procedure, we could make a rotated version of friends by entering make "neworder rotate :friends Because Logo does not have a primitive called ROTATE, we can create a procedure with this name that looks like the following: to rotate :list output sentence butfirst :list first :list end This procedure accepts a list (denoted by the local variable name :LIST) and makes a new list starting with all but the first word, and then appending the first word to the end of the list. The SENTENCE primitive (or native instruction) is used to assemble a list from two parts. The OUTPUT command passes the new list back out of the procedure to any procedure that used ROTATE, or to the command level. Once defined, Logo procedures are treated just as if they were part of the language's native vocabulary. For example, if you were to enter print rotate :friends the list Roy Pat George Pam would appear on the screen. Logo's ability to manipulate lists by taking them apart, adding to them, examining their contents, and altering their order is central to the use of Logo in the creation of knowledge-based programs. For an excellent introduction to the use of lists in the creation of a knowledge "tree" that "sprouts" new nodes as the program gets "smarter," you should read Harold Abelson's discussion of the program Animals in his book "Apple Logo". In addition to the ability to perform list processing and arithmetic, Dr. Logo also supports an excellent turtle graphics environment. While much has been written about turtle graphics, especially on its use with children, it is important to understand that turtle graphics is of tremendous value to expert programmers as well. The power of this graphics environment comes through its description of the shape of an object as a series of incremental steps that create it. Once a procedure describing an object has been written, the object can be displayed at any screen location, orientation, and size without having to tamper with the basic description. For example, the procedure to square :size repeat 4 [forward :size right 90] end can be used to create a square at any screen position, angular orientation, or size. To draw a square at a given place, you first instruct the turtle (a cursor that has both position and orientation) to move to a specific x-y coordinate and heading (angle). Next, you type SQUARE 50, for instance, to create a square with sides 50 units long. This property of turtle graphics procedures, coupled with Logo's capacity to run recursive programs, has allowed the easy exploration of geometrical shapes and their properties. Logo, turtles, and kids ----------------------- Anyone who has watched the personal computer industry for the past few years has probably seen the evolution of certains myths regarding computer languages. Many devotees of BASIC, for example, claim that it is the optimal choice for the home user because of its nearly universal adoption as the default language for personal computers. The fact that BASIC was the only high-level language that was readily available in compact form in the late 1970s is not considered to be relevant by many users. Fortunately, the recent availability of other languages on personal computers (Logo, Pascal, Forth, and Pilot, to name but a few) has afforded programmers other choices. But some of these languages have myths of their own. In the case of Logo, the common myth is that it is a turtle graphics language designed to be used exclusively by children. As evidence in support of this myth, one is pointed to Seymour Papert's book "Mindstorms." It is true that Papert devotes the bulk of his book to the use of turtle graphics as a powerful programming and discovery tool for children, and that he stresses the accessibility of Logo to the young and inexperienced. The problem with the Logo myth is that it suggests that Logo is exclusively for children's use. As with many myths, the reality of the situation is quite different. First, it is true that Logo supports turtle graphics. In this regard, it is similar to some versions of Pascal, Pilot, and Forth. Note also that, while turtle graphics is accessible to children, it also has applications of value to advanced programmers as well. Anyone who doubts this would benefit from reading "Turtle Geometry" by Abelson and diSessa, or "Discovering Apple Logo" by Thornburg. The point is that Logo is no more a "kid's" language than is English. Yes, English is the language of "Mary Had a Little Lamb," but it is also the language of "Moby Dick" and Shakespeare's sonnets. At its base, Logo is a symbol-manipulation language in the finest sense of the word. Rooted in the artificial-intelligence language LISP, Logo allows the user to extend its vocabulary, to use recursion, and to manipulate various types of data in ways that are nearly impossible with languages like BASIC. It would be a shame if the myth of Logo kept serious programmers from exploring a language whose foundation goes to the heart of computer science itself. Programming tools ----------------- Dr. Logo provides many tools to assist the programmer. While smaller Logo systems can adequately survive with a rudimentary procedure editor, larger Logo environments benefit from some of the extra tools that make program analysis and debugging less tedious. Dr. Logo's procedure editor allows the use of both uppercase and lowercase letters for programs and data. Two primitives, UPPERCASE and LOWERCASE, allow the conversion of a word from one case to the other. Also, procedure listings can be indented to make decision branches and nesting easier to see. While not essential to the creation of good programs, such formatted listings are easier to read. While Logo's syntax generally makes procedures easy to read, it is valuable to have comments appended to certain program lines. This ability is provided in Dr. Logo, along with the ability to strip these comments from procedures with the NOFORMAT primitive if more workspace is needed. If the name or syntax of a Logo primitive or editing command is forgotten, online help is available. Once procedures are created, Dr. Logo has several primitives that help show how procedures interact with each other. This is especially important for those Logo enthusiasts who experiment with several coexisting versions of procedures before settling on the final choices. Most versions of Logo will print the names of resident procedures on receiving the POTS commands (Print Out TitleS). If, in Dr. Logo, you enter POTL, the workspace will be examined for all top-level procedures (those not called by other procedures) and their names will be displayed on the screen. If you enter POCALL followed by the name of a procedure, Dr. Logo will examine the calling structure of the named procedure, and print the names of the procedures used by the one mentioned, as well as the names of the procedures used by these secondary procedures, and so on until the calling sequence is complete. This gives a great deal of information on the internal organization of the Logo workspace. If, on the other hand, you enter POREF followed by a procedure name, all the procedures that reference this name will be found and displayed. Many Logo programmers create procedures in a haphazard sequence. Because a listing of multiple procedures follows the sequence in which they were entered, large listings can be hard to assimilate. By using the Dr. Logo FOLLOW command, procedures can be resequenced in any order, thus allowing large listings to be more easily scanned. Once you are ready to try a Logo program, Dr. Logo provides additional tools to assist in debugging. One of these tools allows the text screen to be split into windows corresponding to the command level, a user I/O port, and the debugger. The TRACE command traces the procedure, and displays what is happening and at what level the procedure is, relative to the top (command) level. Because a single recursive procedure (that calls a copy of itself) may oscillate through many levels, knowing the level at which an error occurs is helpful when fixing the fault. The command WATCH allows single-step execution of a procedure, with the ability to change values and see the effect of each statement. The use of multiple text windows in debugging is only one application for this powerful tool. The development of good window-management tools can, by itself, increase the simplicity, flexibility, and power of this programming environment. Applying Dr. Logo in Education ------------------------------ Perhaps because of its historic use as a discovery tool for children (and because of the typically small workspace found with most implementations), Logo is not generally perceived as an application language. It is anticipated that Dr. Logo will prove to be an exception in this regard. The educational applications for Logo have typically focused on the use of turtle graphics. The beauty of turtle graphics is that children simultaneously acquire skills in programming, geometry, and art. Many children who are "turned off" by math have discovered it to be an exciting field through their exploration with turtle graphics. Furthermore, it has been found that, once a child uses Logo to discover new ways of thinking about mathematics, this new way of thinking continues to produce beneficial results -- even if the child is no longer exposed to Logo. In the physical sciences, Logo can be used to construct "microworlds" in which bodies obey different natural laws, such as gravitation. By exploring these artificial microworlds, children can develop better intuitions about the properties of their own corner of the universe. (See "Designing Computer-Based Microworlds" by R.W. Lawler on page 138 of the August 1982 issue of "BYTE" magazine devoted to Logo.) Given Logo's powerful list-processing capability, one would expect it to be of value in the language arts as well. To pick one simple example, suppose a child created several lists called nouns, verbs, adjectives, articles, etc., and assigned appropriate words to each list. The word order in each list can be randomized with the SHUFFLE command, and a random sentence can be constructed by assembling words from each list in a syntactically valid order. Legitimate nonsense sentences can be automatically generated in this fashion (e.g., No yellow toad smells tall people.) while bringing the child to look at and solve the structure of English. The educational value of this program can be seen on several levels. First, if the child creates the lists of words, a misplaced word will show up as a misplaced part of speech. Having a verb appear when a noun is expected results in an obviously invalid sentence structure. The result is a self-reinforcing mechanism for learning the parts of speech. Second, the student can learn to identify valid sentence forms without sample words (sort of the reversal of the traditional parsing process). This helps to cement sentence structure concepts as well. Finally, the student learns some of the challenges awaiting those who want to create natural-language interfaces between people and computers. Dr. Logo in Business -------------------- While Logo is not usually thought of as a language for business applications, Dr. Logo has several characteristics that may change this perception. The creation of an interactive illustration generator using an inexpensive graphics tablet is quite easy in Dr. Logo. In addition to business graphics, the list processing capability of Dr. Logo makes it suitable for database management. In fact, one might envision incorporating some of the results of research in natural-language understanding to generate a query system that responds to questions such as: "If we increase our salaries by 10 percent this year and increase our sales by 20 percent next month, what will our profit be in the fourth quarter?" There is no question that many business applications will be found for Dr. Logo, but it is premature to set limits on the scope of these applications. Dr. Logo in Artificial Intelligence ----------------------------------- There has been much talk lately about knowledge-based or "expert" systems. The noble efforts of personal computer software experts notwithstanding, sophisticated microcomputer programs that can adapt to various queries are few and far between. The major reason for this is the inadequacy of most computer languages for dealing with the types of data and operations natural to adaptive systems. Because of Dr. Logo's close connection with LISP, we expect to see artificial-intelligence techniques appearing in personal computer software, rather than being limited to university and large industrial research centers as they have been in the past. This movement is valuable for several reasons. First, it will help to demystify artificial-intelligence research. Second, it will result in the application of advances in artificial intelligence to the development of practical programs. To pick one example, suppose you had a computer program (called car repair) that allowed the following dialogue: User: I hear noises when I steer the car. Computer: Do you think the problem is in your steering mechanism? User: Yes, I think so. Computer: Do you have power steering? User: Yes. Computer: Is the noise loudest when you turn the steering wheel? User: Yes, but I hear it when the car is idling, too. Computer: You should check the level of your steering fluid before proceeding. Do you know how to do that? User: Yes. Computer: Fine. Check the fluid level. If it is low, fill the reservoir and see if the problem is fixed; otherwise, we will continue to explore other causes. Programs that allows this type of interaction can be used for many diagnostic applications, and might be far more valuable applications for home computers than checkbook balancers or recipe files. Domestic applications for artificial intelligence represent a sleeping giant. The list-processing capability and large workspace of Dr. Logo will allow this giant to be awakened, and will enable the creation of a whole new class of applications software. Dr. Logo is the first of a new family of languages that promises not only to change our programming style, but to alter the way we think about computing itself. References ---------- Logo: 1. "Apple Logo" Abelson, Harold BYTE/McGraw-Hill, 1982 2. "Turtle Geometry: The Computer as a Medium for Exploring Mathematics" Abelson, Harold and Andrea diSessa MIT Press, 1981 3. Special Logo Issue, BYTE, August 1982 4. "Mindstorms: Children, Computers, and Powerful Ideas" Papert, Seymour Basic Books, 1980 5. "Discovering Apple Logo: An Invitation to the Art and Pattern of Nature" Thornburg, David Addison-Wesley, 1983 Artificial Intelligence: 1. "Artificial Intelligence: An Introductory Course" Bundy, A., ed. North Holland, 1978 2. "Artificial Intelligence" Winston, Patrick Addison-Wesley, 1977 LISP: 1. Special LISP Issue, BYTE, August 1979 2. "LISP 1.5 Programmer's Manual" McCarthy, John et al. MIT Press, 1965 3. "LISP" Winston, Patrick and Berthold Horn Addison-Wesley, 1981 Listing ------- to graphics ; ; A sample business graphics program for bar graphs. ; make "screen.height 190 make "screen.width 310 make "yfactor .25 make "zfactor .575 make "zdeg 22.5 make "xmin -139 make "xmax 139 make "ymin -79 make "ymax 119 make "return char 13 get.request end to get.request (local "reply "h.or.v "s.or.o "2.or.3) cleartext make "reply prompt [Horizontal or vertical bars (h or v)] "char if :reply = "h [make "h.or.v "h] [make "h.or.v "v] if :reply = :return [stop] make "reply prompt [Solid or open bars (s or o)] "char if :reply = "s [make "s.or.o "s] [make "s.or.o "o] if :reply = :return [stop] make "reply prompt [2 or 3 dimensional (2 or 3)] "char if :reply = 2 [make "2.or.3 2] [make "2.or.3 3] if :reply = :return [stop] make :reply prompt [Values to be graphed] "list if "reply = [] [stop] bar.graph :h.or.v :s.or.o :2.or.3 :reply get.request end to prompt :text :type local "reply (type :text ": char 32) if :type = "char [make "reply readchar print :reply output :reply] [output readlist] end to bar.graph :h.or.v :s.or.o :2.or.3 :values cleartext (local "max.value "min.value "origin "width "depth "axis "reply "graph.width "graph.height "proc "spacing) if emptyp :values [stop] make "max.value 0 make "min.value 999999999 if :h.or.v = "h [make "origin list :xmin :ymax make "graph.height :screen.width make "graph.width :screen.height make "axis 90] if :h.or.v = "v [make "origin list :xmin :ymin make "graph.height :screen.height make "graph.width :screen.width make "axis 0] if :2.or.3 = 2 [make "spacing (:graph.width / count :values) * :yfactor] [make "spacing (:graph.width / count :values) * :zfactor] if :2.or.3 = 2 [make "width (:graph.width / count :values) * (1 - :yfactor)] [make "width (:graph.width / count :values) * (1 - :zfactor)] make "depth :width * :zfactor minmax :values make "values scale :values :graph.height * .8 / :max.value cleanup penup setpos :origin pendown if :h.or.v = "h [line [] list :screen.width ycor] [line [] list xcor :screen.height] penup setpos :origin pendown draw.bars :axis :width :spacing :2.or.3 :values splitscreen setcursor [0 23] type [Press ENTER to Continue...] make "reply readchar end to minmax :list if emptyp :list [stop] if first :list > :max.value [make "max.value first :list] if first :list < :min.value [make "min.value first :list] minmax butfirst :list end to scale :list :factor if emptyp :list [output []] output sentence (:factor * first :list) scale butfirst :list :factor end to cleanup hideturtle setbg 0 penup home clean pendown end to draw.bars :axis :width :spacing :2.or.3 :values if emptyp :values [stop] setheading :axis draw.1.bar :s.or.o :2.or.3 first :values :width :depth :zdeg setheading :axis + 90 forward :spacing + :width draw.bars :axis :width :spacing :2.or.3 butfirst :values end to draw.1.bar :s.or.o :2.or.3 :height :width :depth :zdeg (local "origin "direction) make "origin pos make "direction heading if :s.or.o = "o [make "proc "open.bar] [make "proc "solid.bar] run (list :proc :height :width) if :2.or.3 = 2 [stop] forward :height right 90 - :zdeg forward :depth right :zdeg forward :width right 180 - :zdeg forward :depth back :depth left 90 - :zdeg forward :height right 90 - :zdeg forward :depth penup setpos :origin pendown setheading :direction end to open.bar :height :width repeat 2 [forward :height right 90 forward :width right 90] end to line :pos1 :pos2 if not emptyp :pos1 [penup setpos :pos1 pendown] make "pos1 pos setheading towards :pos2 forward sqrt sum sq ((first :pos1) - (first :pos2)) sq ((last :pos1) - (last :pos2)) end to sq :num output :num * :num end to solid.bar :height :width (local "course "origin) make "course heading make "origin pos repeat :width / 2 [forward :height right 90 forward 1 right 90 forward :height left 90 penup forward 1 pendown left 90] if remainder :width / 2 = 1 [forward :height] penup setpos :origin pendown setheading :course end EOF