commands (which usually do something-effects-but do not return a value) like print.REPEAT 36 RT 10]Įach line is made up of function calls, of which there are two types: Loops may be nested, giving results with little effort.
The command FD 100 LEFT 90 is executed four times.Īn approximation of a circle can be constructed easily with 360 small rotations and a step forward: REPEAT 360. There are three loop (repeat) commands REPEAT is one. The Hello World program in Logo looks like this: draws a square with sides 100 units long FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FD 100 RT 120 FD 100 RT 120 draws a triangle There are three commands to process property list. They represent four flavours of template iteration, known as explicit-slot, named-procedure, named-slot (or Lambda), and procedure-text.Ī property list is a special list where the odd number items are property names, and the even are property values. There are several of these template commands with names like MAP, APPLY, FILTER, FOREACH, REDUCE and CASCADE. OPERATION Įach of the commands is applied in turn to each of the data items. Logo also provides list-based control structures. Recursion is Logo's preferred processing paradigm. Logo provides several common control structures. Recursion rather than iteration is the natural method to process lists.A list can be considered to be a queue with the operators queue and dequeue, or a stack with the operations push and pop.Data elements are added using sentence, fput, and lput. Data are extracted using the operations first, butfirst, last, butlast, butmember, member, and item. This data type has the advantage over arrays that it is infinitely expandable.Operators exist to convert words into lists, and lists into arrays and back again.Logo inherits lists from Lisp, and they are its main method to store vectors. Calling a procedure with inputs (the name usually used for arguments in the Logo literature) also creates local variables that hold the argument values. Variables do not have to be declared before use their scope is then global.Ī variable may be declared local, then its scope is limited to that procedure and any procedures that it calls, which is termed dynamic scope. From a programmatical perspective, the first argument to make is passed by reference, while the second is passed by value. The effect of make is to place the result into the first parameter. "3 evaluates to 3, and :y takes the contents of the thing called y, these are summed giving a number. sum takes two 'parameters' and is an 'operation', thus the calculation is possible. Make takes 2 parameters, the second of which here is sum :y "3. x := y + 3) is handled in Logo with the make command, as exemplified by these two equivalent statements: For users from other programming languages: the doublequote is not paired as opening and closing quotes.Ī number is a special case of self-evaluation it really could be written with a quote. The doublequote ( ") means the word is evaluated as itself, or its value after evaluation is the same as it was before.This is an extremely useful symbol that keeps reminding students that a variable is really a place in memory. The interpreter detects the datatype by context. The turtle can be set to erase anything below it, using the command PENERASE (PE), while the pen can be set to start drawing again with the command PENPAINT (PPT), in UCBLogo.įD 20 draw a line and move PENUP lift the pen so it draws nothing FD 20 move and not draw PENDOWN lower the pen so it draws again FD 20 draw a line and move PENUP lift the pen so it draws nothing FD 40 move and not draw PENDOWN lower the pen so it draws again RT 20 rotate right (clockwise) 20 degrees Data Using the turtle analogy, the turtle's pen must paint, and the turtle's pen must erase. The process is the same, except that in the former, a line is deposited on the display device and in the latter a line is removed. Animations require both the ability to draw and to erase shapes. Logo was designed in spirit of low threshold and no ceiling, which enables easy entry by novices and yet meet the needs of high-powered users. MSWLogo and its successor FMSLogo, for Microsoft Windows, are commonly used in schools in the United Kingdom and Australia. UCBLogo has a rudimentary graphical user interface (GUI), so several projects exist that provide a better interface. 4.4 Transcribe a sentence into Pig latin example.4.3 Define and use a procedure to compute plurals.4.2 Define and use a procedure which calculates the average of its numeric arguments.