FANDOM


Logo syntax is similar to that of written language in that spaces are the most common way to separate one element from another. When you type a Logo line, each individual element is separated from the one before and after by one or more spaces. When Logo reads the line after you press the ENTER key, it identifies each individual element as a primitive, procedure, number, word, list, property list, or array and operates according to set rules for responding to each command and object.

Parsing

The process Logo uses to interpret and carry out a line of commands is called parsing. As a general rule, Logo reads elements in a line one at a time from left to right and processes them in that order. Most Logo primitives and all user-defined procedures are used by invoking the procedure name and then the inputs to the procedure to conform to left to right parsing (which is also the way we read). Logo identifies a command, checks its memory for the number of inputs required by the command, and then proceeds from left to right across the line to identify the input.

Arithmetic infix operators are the major exception to this rule. Infix operators (+, -, *, /, <, >, <=, >=, =) can come between their inputs (although they can also precede their inputs). In that case, Logo looks on either side of an infix operator to identify its inputs.

Delimiters

The basic way to indicate the beginning and end of each element in a Logo command line is with a space. The space is the basic delimiter in Logo, or the means used to indicate the beginning or end of a Logo element.

Logo recognizes other characters as delimiters as well. These include the infix operators (+, -, *, /, <, >, <=, >=, =) as well as quotation marks (") which identify words, colons (:) which identify names, square brackets ([]) which identify lists, and parentheses (()) which group elements together. Spaces are optional before and after these characters in a Logo line. For example, Logo will understand if you type:

? IF(3+5)=(4*2)PRINT"RIGHT!

RIGHT!

?

Parentheses

Parentheses are used in Logo to group objects together differently than Logo would ordinarily. When parentheses are used with arithmetic operators, calculations are performed in a different order from the standard mathematical hierarchy. For example:

? 16 - 4 / 2

Result: 14

? (16 - 4) / 2

Result: 6

?

Parentheses can also be used with primitives and user-defined procedures that accept a varying number of inputs. If you give more inputs to a procedure than Logo expects, Logo will stop because it doesn't know what to do with the extra input. For example, Logo expects only one input with PRINT. If you type:

? PRINT "HI "THERE

Logo prints HI and then attempts to interpret the next input, THERE. Since you have not told Logo what to do with the input word THERE, Logo outputs it as a result:

Result: THERE

and stops.

PRINT can take a variable number of inputs if it and its inputs are inside parentheses. For example:

? (PRINT "HI "THERE)

HI THERE

?

This use of parentheses is valid for Logo primitives and user-defined procedures that are specified to use optional variables. See the section on Optional Variables for information on creating procedures that can have variable inputs.

Punctuation

It is always good practice to close parentheses (which group Logo elements) and brackets [which identify Logo lists] by providing a right parenthesis or bracket for each left parenthesis or bracket on a Logo line. As a convenience, when you end a Logo line by pressing ENTER, any open brackets or parentheses are closed. For example:

? REPEAT 3 [(PRINT [GOOD MORNING] [FRIEND!

This command is the same as:

? REPEAT 3 [(PRINT [GOOD MORNING] [FRIEND!])]

Occasionally you may want Logo delimiter characters to act as normal characters rather than assume their special meaning. For example:

? PRINT "HOWDY-DOODY

DOODY is not a Logo procedure.

?

In this case, Logo is interpreting the dash as a subtraction operator and cannot find any numbers to subtract. Use the backslash key (\) to indicate to Logo that the following character does not have its special Logo meaning.

? PRINT "HOWDY\-DOODY

HOWDY-DOODY

?

The backslash quotes the character following it, removing any special meaning in Logo. The system name :DELIMITER indicates the character that can be used to quote a group of characters. When Logo starts up the group delimiter is the vertical bar (|).

? PRINT "*/+#&

Bad number syntax.

? PRINT "|*/+#&|

  • /+#&

?

In a manner similar to parentheses and brackets, Logo will close an open group delimiter character when you press ENTER.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.