HiLogo Lisp/Logo Interpreter

User Guide

Version 2.2

Copyright (c)1991-1998
By Eamonn F. Martin
All rights reserved

Table of Contents

  1. Turtle Movement
  2. Turtle Graphics
  3. General commands
  4. Variables
  5. Expressions
  6. List Processing
  7. Process control
  8. Procedures
  9. Files and Directories


Turtle Movement

Relative reference

FORWARD n
Move all active turtles forward n units. Draws a line if pen is down. The size of a unit can be modified using SCALE.
BACKWARD n
Move all active turtles backward n units. Draws a line if pen is down The size of a unit can be modified using SCALE.
MOVEX n
Move all active turtles n units along x coordinate without drawing a line. The size of a unit can be modified using SCALE.
MOVEY n
Move all active turtles n units along y coordinate without drawing a line. The size of a unit can be modified using SCALE.
LEFT n
Turn all active turtles left n degrees.
RIGHT n
Turn all active turtles right n degrees.

Absolute Reference

SETX n
In graphics mode, set x co-ordinate of all active turtles to n (centre = 0). In text mode, SETX positions the text-cursor at column n.
SETY n
In graphics mode, set y co-ordinate of all active turtles to n (centre = 0). In text mode SETY positions the text cursor at line n.
SETPOS x y
Set x and y coordinates of all active turtles to x and y respectively (screen centre = 0 0). Equivalent to SETX x SETY y. SETPOS can also be used in text mode to position the text cursor (top-left = 1 1).
SETH n
Set heading of all active turtles to n degrees (straight up = 0).

Movement Ratio

All turtle movement is in units. The size of a unit can be modified, using the SCALE command, to shrink or enlarge a picture.

SCALE x or SCALE n TO m
The first format sets the turtle movement ratio to the absolute value x. For example SCALE 2 will set the units of movement to twice the normal size. The second format will multiply the current movement ratio by a factor of n/m. To double unit size for example, use SCALE 2 TO 1.
UNSCALE
Reset movement ratio to normal. Equivalent to the command SCALE 1.


Turtle Graphics

CENTRE
Reset all active turtles to screen centre with their initial headings. Leaves the graphics screen intact.
SHOW
Display turtle. All active turtles are displayed.
HIDE
Hide turtle. All active turtles are hidden (but still active).
LIFT
Lift pen. Active turtles will not draw a line when moved using FORWARD or BACKWARD.
DROP
Drop pen. Active turtles will draw a line when moved using FORWARD or BACKWARD.
TELL <expression>
Activate all turtles specified by the expression, which must be either a single number or a numeric list. All turtle commands are addressed to all active turtles. There are eight turtles available, numbered 1 to 8. Inactive turtles are not displayed.
LABEL <expression>
Write the value of the expression at all active turtle positions.

FILL
Fills a region with the turtle's pen colour, starting from its current position. The region must be bounded by the turtle's pen colour.
SETPC n
Set pen colour of all active turtles to n.
SETC n
Set colour of all active turtles to n.
SETBG n
Set background colour to n.
WHERE
In graphics mode, WHERE outputs a list containing the co-ordinates and headings of all active turtles. In text mode, WHERE outputs a list containing the co-ordinates of the text cursor.
WHEREX / WHEREY
In graphics mode, these two functions output lists which contain the horizontal (X) and vertical (Y) co-ordinates (respectively) of all active turtles. In text mode, they output the X and Y co-ordinates of the text cursor.
HEADING
Output a list containing the headings (in degrees) of all active turtles.


General commands

BEEP <pitch> <duration>
Turn on the internal speaker for 'duration' milliseconds at the specified pitch.
PRINT <expression>
Print the value of the expression at the command line.
CLEAN
Clear the screen. CLEAN does not affect turtle positions in graphics mode.
CLEAR
Initialise turtle-graphics mode and clear the screen. Resets all turtles to screen centre with their initial headings.
TEXT
Initialise text mode and clear the screen. The whole screen is used to display text only. Turtle-graphics functions are not available in text mode.
HELP
Invoke the LOGO Help system.
BYE
Leave LOGO, return to the operating system.


Variables

Variables are like storage boxes with names. Each box can contain either a number or a list.

MAKE <variable> <expression>
Assign the value of expression to variable. If the variable does not exist, it is created at the global level. Global variables remain permanently in memory and are available to all procedures.
LOCAL <variable>
Create a 'local' variable. Local variables defined within a procedure will only exist inside that procedure. Parameters passed to a procedure are always local.
BUG <variable>
Enable variable 'bugging'. Whenever the named variable is changed, its value is displayed on the screen.
UNBUG <variable>
Disable 'bugging' of the named variable.
RESET
Clear all active variables from memory. Local variables are cleared automatically when the procedure in which they are defined terminates. Global variables remain in memory permanently until removed by RESET or NEW.
VARIABLES
Print a list of variables (and their values) currently active in memory.


Expressions

Expressions may comprise any combination of values, lists, variables, procedures or functions. The arithmetic operators (+-*/ etc.) cannot be applied to non-numeric lists, but lists may be compared. Lists are converted to numeric values whenever possible. Parenthesis may be used to force the order of arithmetic evaluation.

Numeric Functions

INT n   Integer part of n
FRAC n  Fractional part of n
SQT n   Square root of n
SIN n   Sine of n
COS n   Cosine of n
TAN n   Tangent of n
PICK n  Random value (1 - n)
RANDOM  Random value (0 - 1)
KEYQ    True if key pressed
KEY     ASCII code of key
MEMLEFT Free memory (bytes)

Boolean operators

NOT n    TRUE if n is FALSE,
         FALSE if n is TRUE
n OR m   TRUE if n or m
         (or both) is TRUE
n XOR m  TRUE if either n or
         m (but not both) is
         TRUE
n AND m  TRUE if both n and
         m are TRUE
This table shows the order in which operators and functions in expressions are evaluated.

( )
NOT  <Numeric functions>
*  /
+  -
<  <=  >  >=
=  <>
AND
OR  XOR

List Processing Functions

FIRST <list> / FIRSTC <list>
Output the first word or character in a list. FIRSTC may only be used with either single-word lists or numbers.
LAST <list> / LASTC <list>
Output the last word or character in a list. LASTC may only be used with either single-word lists or numbers.
BUTFIRST <list> / BUTFIRSTC <list>
Output list minus its first word or character. BUTFIRSTC may only be used with either single-word lists or numbers.
BUTLAST <list> / BUTLASTC <list>
Output list minus its last word or character. BUTLASTC may only be used with either single-word lists or numbers.
COUNT <list> / COUNTC <list>
Output the number of items in a list. COUNTC outputs the number of characters in a single-word list or number.
ITEM <num> <list>
Output element number num in list. If num is out of range, ITEM returns an empty list.
JOIN <list1> <list2>
Output a list consisting of list1 appended to list2. The two lists are separated by a space so that each remains separate.
BOND <list1> <list2>
Output a list consisting of list1 appended to list2. The two lists are not separated so that adjacent elements become one.
RUN <list>
Evaluate list as a command or command sequence, allowing commands to be treated as variables.
VAL <list>
Output the value returned by evaluating list as a function or variable name. This allows lists to contain the names of sub-lists and functions.
READ / READC
Output a list (READ) or a character (READC) read from the keyboard.
ASC <list>
Outputs the ASCII code of the first letter of a list.
CHR <expr>
Outputs the character whose ASCII code is <expr>.


Process Flow Control

These commands control the flow of execution of a process.

REPEAT n <list>
Repeat a list of commands n times.
DO <list> {UNTIL} <condition>
Repeat commands in list until condition evaluates to TRUE. The command list will be executed at least once, as the condition is evaluated last.
WHILE <condition> <list>
Repeat commands in list while condition evaluates to TRUE. The condition is evaluated first, so the command list may not be executed at all.
IF <condition> <list1> {<list2>}
If condition evaluates to TRUE, the commands in list1 are executed. Otherwise, if list2 is given, its commands are executed instead.
STOP
Terminate execution of a procedure. Procedures can be stopped at any time by pressing the ESCAPE key (Esc).


Procedures

A procedure is a named list of commands entered via the LOGO text editor (or loaded from disk). These can be primitive (built-in) commands or other procedures. The top line of a procedure must hold its name, optionally followed by the names of parameters to be received from the calling process (separated by spaces).

Procedure Input


Procedures are called by entering their name followed by any values which need to be passed as parameters. At each entry procedures create local variables to hold each value received. These are available to sub-procedures but are destroyed on exit. Procedures can therefore be called recursively.

Procedure Output


Procedures can use the OUTPUT (or RETURN) command to return either a number or a list as output. For example, to return the character-list 'Error', use:

OUTPUT [Error]

The output can be used in an expression or by other procedures or by commands like MAKE or SAY.

Procedure Commands

NEW
Remove all procedures and variables from memory.
BUILD <title>
Invoke the editor to build a new procedure with the name title. If a procedure with that title already exists, the new procedure will replace it. If title is not given the previous title is used, if one exists.
EDIT <title>
Invoke the editor to edit an existing procedure with the name title. The named procedure must already exist in memory. If title is not given the previous title is used, if one exists.
SCRAP <title>
Remove the procedure title from memory.
TRACE
Activate trace facility. Each procedure line that is executed is printed on the command line. This is useful for debugging (correcting) your procedures.
UNTRACE
Deactivate trace facility.
TITLES
Print a list of procedures in memory.


Files and Directories

LOAD <fname>
Load procedures in file fname from disk. Procedures from the file will replace any procedures in memory that have the same name.
SAVE <fname>
Save all procedures in memory to file fname on disk.
ERASE <fname>
Delete a file on disk.
FILES <path>
Print a list of files on disk. An path must be given which may include standard DOS wildcards. If an empty list is specified the default path (*.LOG) is used.
CHDIR <path>
Change the current working directory.
MKDIR <path>
Create a sub-directory.
RMDIR <path>
Remove a sub-directory. The sub-directory must be empty.