Turtle LibreLogo
Tilbake til startsida
 

 

Grammar

All programming languages ​​have their own rules for how text and commands should be written called grammar. So in Libre Logo too. This chapter is about the very simple grammar used in LibreLogo.

Error messages

The error message system in Libre Logo will as a rule only report that there are errors in the line number xx. The cursor will move to the code line in which the error is found. Sometimes also a text with proposals for what the error may be. But mostly you will have to diagnose the error yourself. Most common errors are misspelling and wrong syntax for commands and variables.

Upper case and lower case

In Libre Logo you can use upper- and lower- case letters in commands and color names. If you types PenColor 'blue' or PENCOLOR 'blue' or other combinations, the result each time will be the color of the pen is set to blue. On these webpages I have written commands in upper case to show that they are commands.

In name of variables, upper case and lower case is not the same thing. Variable names must always be used as they are defined. If you defined: :color = 'blue' the command PENCOLOR :Color generate the error message “Unknown name: '_Color.'”. Very often the cause of such failures is that LibreOffice is set to automatically use upper case after line break if you omit the colon before the name of the variable

Variables and variable names

In LibreLogo you can name a custom variable for what you want. In other variants of Logo the variable names must start with a colon (:). This can be used also in Libre Logo, but is not necessary. It may still be advisable to use colon, so that it is easier to see that a name is a variable and not a function

Variable have no type declaration. This means that one custom variable can contain an integer, the next time a decimal numbers or text.

Values ​​in and out of variables.

For custom variables you add values by using the equal sign. :x = 5.

For pre defined variables you add values by writing a space between the name of the variable and the value. RIGHT 90.

You read the value of a variable, custom or pre-defined, using the equal sign: :x = PENSIZE.

This can be used when you change a variable inside a function, but wish to carry on with the original value of the variable outside the function. For example if you use green or another color as the normal painting color, but will use blue color for a specific figure, you may be doing it this way:

:f = PENCOLOR
PENCOLOR 'blue'
{ Before you get out of the function, reset color: }
PENCOLOR :f

Brackets

Libre Logo user square brackets ([]) both to set lists and to define program blocks. In a list there must not be space between the first brackets and the first list item, and no space between the last element and the last brackets. :l = [1, 2, 3, 4]. In program blocks there must be spaces or line breaks after the first brackets and before the last one. REPEAT [ LEFT 90 BACK 10 ].

Function declarations TO and END should not have brackets.

If you normally use ordinary parentheses in expressions to make them easier to understand, you can do it in LibreLogo too. The call of the function star can be written either as star 50 'yellow' or as star (50 'yellow')

Necessary brackets

Sometimes Libre Logo is not able to sort out what you actually mean with a command. Then grouping your writing using ordinary parenthesis can be of some help. If, for example you write the command :s = STR 5 + " persons" you get an error message. LibreLogo think " persons" shall be attached to the number 5. If you change the phrase to :s = (STR 5) + " persons" LibreOffice will understand the meaning.

This also applies in mathematical expressions. Here parentheses are used in the usual way to change the order of calculation. :x = (2 + 8) * 10.

Quotation characters

In most programming languages, double (") and single (') quotation characters are used for example to mark string expressions. So also in Libre Logo.

Although strings are marked with double or single quote characters, a single word can be marked as a string before the word. PRINT "word works fine, so does of course PRINT "word" too.


© Context and design: Kolbjørn StuestølStuestøl homesite (in Norwegian)Modified February 11 2016