LOGO

User Manual for the TI-89/92+/V200 Implementation of Logo

Scott Noveck



Introduction

Overview

Copyright (C) 2002 by Scott Noveck
This documentation is based on that of Berkely Logo, Copyright (C) 1993 by the Regents of the University of California

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

This implementation of Logo focuses on the graphical and turtle movement aspects of the Logo language.  It does not attempt to implement the LISP-derived list processing features, text manipulation, or other advanced data types found in Berkeley Logo and other fully-featured distributions.

Tokenization

Users familiar with other dialects of Logo should pay particular attention to this section.  Some of the tokenization rules have been modified slightly in this implementation.

This implementation of Logo ignores whitespace and text formatting.  You may insert spaces and end lines anywhere so long as they do not split apart whole words/tokens.

All commands, including both built-in tokens and user-specified procedure and variable names, are case-insensitive.  Case of letters is preserved in everything you type, however.

Variable names, which include any strings begining with the colon (:) character, are delimited by a space, a bracket, a parenthesis, a comment character (see below), or an infix operator (these include +-*/%^=<>, along with the calculator-specific negative, not-equal, less-than-or-equal, and greater-than-or-equal characters). Note that the colon character is not  a delimiter.

All other words, including procedure names and built-in tokens, are delimited by a space, a square bracket, a parenthesis, or a comment character (see below).  Note that this means procedure names may contain infix operators, such as one-two, but variable names may not.

A semicolon or calculator-specific comment character (diamond-) on the 89, 2nd-x on the 92+/V200) begins a comment in an instruction line. Logo ignores characters from the beginning of the comment to the end of the line.

Implementation-Specific Changes

This Logo implementation differs slightly from past implementations in several aspects.  Some of the changes are addressed here:

Functions with a variable number of inputs:
Some Logo functions, both built-in and user-defined, can take a variable number of inputs, rather than a fixed number.  For instance, the product procedure can take only two inputs, or it can take more.  In most other Logo implementaions, if a procedure is passed a number of inputs other than the default, it must be surrounded by parentheses, as in (product 2 3 4); this is sign of Logo's parent language, LISP.  This implementation works slightly differently - procedures like product will continue treating the tokens that follow them as inputs until it finds one that would not be a valid input.  This is done for convenience, as it eliminates the need for extra parentheses in many instances.  However, in some instances this may cause problems, such as difference product 2 3 4.  In this example, extra parentheses should be added to clarify the desired operation, resulting in difference (product 2 3) 4.  When using any procedure that can take a variable number of inputs, you should keep in mind that parentheses may be necessary.

Calculator-specific characters: The calculators have access to several characters that are not present in other environments.  Those used by Logo include the not-equal character, the less-than-or-equal character, the greater-than-or-equal character.  On other implementations, for instance, less than or equal would be dentoed by (OR num1<num2 num1=num2).  The calculator also has a special comment character; both this character and the semicolon can be used to denote comments.

Start of execution: The first function in a program, which be the same as that program's filename, is considered the program's entry point.  It is this function that is run by the "run program" command.  Inputs to this function have special handling; see the documentation for to for more information.

Specific commands: This implementation of Logo has a few specific commands that may differ from their counterparts in other implementations.  Among these are to, local, make, and for.


Arithmetic

Numeric Operations

sum

SUM num1 num2
SUM num1 num2 num3 ...
num1 + num2

outputs the sum of its inputs.

difference

DIFFERENCE num1 num2
num1 - num2

outputs the difference of its inputs.

minus

MINUS number
- number
- number (where - is the calculator-specific negative sign)

outputs the negative of its input. Minus sign means unary minus if it is immediately preceded by something requiring an input.  There is a difference in binding strength between the two forms:

MINUS 3 + 4     means   -(3+4)
- 3 + 4 means (-3)+4

Also note that there is a difference in binding strength from the calculator's built-in mathematical functions.  The negative sign binds tighter than the expontiation (power) operation, so -3^2 is the same as (-3)^2 or 9, not -(3^2) or 9.  This order of operations is more common than the calculator's default.

Note that in many situations, using the minus sign for negation may be problematic.  For instance, because Logo is not sensitive to whitespace, setxy 10 -10 will be read as setxy 10-10, or setxy 0, and then look at the following text for a second input.  Instead, use the calculator-specific negative sign or parentheses, such as in setxy 10 (-10).

product

PRODUCT num1 num2
PRODUCT num1 num2 num3 ...
num1 * num2

outputs the product of its inputs.

quotient

QUOTIENT num1 num2
QUOTIENT number
num1 / num2

outputs the quotient of its inputs. The quotient of two integers is an integer if and only if the dividend is a multiple of the divisor. (In other words, QUOTIENT 5 2 is 2.5, not 2, but QUOTIENT 4 2 is 2, not 2.0 -- it does the right thing.) With a single input, QUOTIENT outputs the reciprocal of the input.

remainder

REMAINDER num1 num2
num1 % num2

outputs the remainder on dividing num1 by num2; both must be integers and the result is an integer with the same sign as num1.

modulo

MODULO num1 num2

outputs the remainder on dividing num1 by num2; both must be integers and the result is an integer with the same sign as num2.

int

INT number

outputs its input with fractional part removed, i.e., an integer with the same sign as the input, whose absolute value is the largest integer less than or equal to the absolute value of the input.

Note: Inside the computer numbers are represented in two different forms, one for integers and one for numbers with fractional parts. However, on most computers the largest number that can be represented in integer format is smaller than the largest integer that can be represented (even with exact precision) in floating-point (fraction) format. The INT operation will always output a number whose value is mathematically an integer, but if its input is very large the output may not be in integer format. In that case, operations like REMAINDER that require an integer input will not accept this number.

See section remainder

round

ROUND number

outputs the nearest integer to the input.

sqrt

SQRT number

outputs the square root of the input, which must be nonnegative.

power

POWER num1 num2
num1 ^ num2

outputs num1 to the num2 power. If num1 is negative, then num2 must be an integer.

exp

EXP number

outputs e (2.718281828+) to the input power.

log10

LOG10 number

outputs the common logarithm of the input.

ln

LN number

outputs the natural logarithm of the input.

sin

SIN degrees

outputs the sine of its input, which is taken in degrees.

radsin

RADSIN radians

outputs the sine of its input, which is taken in radians.

cos

COS degrees

outputs the cosine of its input, which is taken in degrees.

radcos

RADCOS radians

outputs the cosine of its input, which is taken in radians.

tan

TAN degrees

outputs the tangent of its input, which is taken in degrees.

radtan

RADTAN radians

outputs the tangent of its input, which is taken in radians.

arcsin

ARCSIN number

outputs the arcsine, in degrees, of its input.

radarcsin

RADARCSIN number

outputs the arcsine, in radians, of its input. 

arccos

ARCCOS number

outputs the arccosine, in degrees, of its input.

radarccos

RADARCCOS number

outputs the arccosine, in radians, of its input.

arctan

ARCTAN number
ARCTAN x y

outputs the arctangent, in degrees, of its input. With two inputs, outputs the arctangent of y/x, if x is nonzero, or 90 or --90 depending on the sign of y, if x is zero.

radarctan

RADARCTAN number
RADARCTAN x y

outputs the arctangent, in radians, of its input. With two inputs, outputs the arctangent of y/x, if x is nonzero, or pi/2 or -pi/2 depending on the sign of y, if x is zero.

The expression 4*(RADARCTAN 1) or 2*(RADARCTAN 0 1)can be used to get the value of pi.

Numeric Predicates

equalp

EQUALP num1 num2
EQUAL? num1 num2
num1 = num2

outputs TRUE if its first input is equal to its second.

notequalp

NOTEQUALP num1 num2
NOTQUAL? num1 num2
num1 ? num2 (where ? is the calculator-specific not-equal symbol)

outputs TRUE if its first input is not equal to its second.

lessp

LESSP num1 num2
LESS? num1 num2
num1 < num2

outputs TRUE if its first input is strictly less than its second.

greaterp

GREATERP num1 num2
GREATER? num1 num2
num1 > num2

outputs TRUE if its first input is strictly greater than its second.

lessequalp

LESSEQUALP num1 num2
LESSEQUAL? num1 num2
num1 < num2 (where < is the calculator-specific less-than-or-equal symbol)

outputs TRUE if its first input is less than or equal to its second.

greaterequalp

GREATEREQUALP num1 num2
GREATEREQUAL? num1 num2
num1 > num2 (where > is the calculator-specific greater-than-or-equal symbol)
outputs TRUE if its first input is greater than or equal to its second.


Random Numbers

random

RANDOM number

outputs a random nonnegative integer less than its input, which must be an integer.

rerandom

RERANDOM
RERANDOM seed

command. Makes the results of RANDOM reproducible. Ordinarily the sequence of random numbers is different each time Logo is used. If you need the same sequence of pseudo-random numbers repeatedly, e.g. to debug a program, say RERANDOM before the first invocation of RANDOM. If you need more than one repeatable sequence, you can give RERANDOM an integer input; each possible input selects a unique sequence of numbers.

Bitwise Operations

bitand

BITAND num1 num2
BITAND num1 num2 num3 ...

outputs the bitwise AND of its inputs, which must be integers.

See section and

bitor

BITOR num1 num2
BITOR num1 num2 num3 ...

outputs the bitwise OR of its inputs, which must be integers.

See section or

bitxor

BITXOR num1 num2
BITXOR num1 num2 num3 ...

outputs the bitwise EXCLUSIVE OR of its inputs, which must be integers.

See section or

bitnot

BITNOT number

outputs the bitwise NOT of its input, which must be an integer.

See section not

ashift

ASHIFT num1 num2

outputs num1 arithmetic-shifted to the left by num2 bits. If num2 is negative, the shift is to the right with sign extension. The inputs must be integers.

lshift

LSHIFT num1 num2

outputs num1 logical-shifted to the left by num2 bits. If num2 is negative, the shift is to the right with zero fill. The inputs must be integers.


Logical Operations

and

AND bool1 bool2
AND bool1 bool2 bool3 ...

outputs TRUE if all inputs are TRUE, otherwise FALSE. All inputs must be TRUE or FALSE.

or

OR bool1 bool2
OR bool1 bool2 bool3 ...

outputs TRUE if any input is TRUE, otherwise FALSE. All inputs must be TRUE or FALSE.

not

NOT bool

outputs TRUE if the input is FALSE, and vice versa.


Graphics

Turtle Motion

forward

FORWARD distance
FD distance

moves the turtle forward, in the direction that it's facing, by the specified distance (measured in turtle steps).

back

BACK distance
BK distance

moves the turtle backward, i.e., exactly opposite to the direction that it's facing, by the specified distance. (The heading of the turtle does not change.)

left

LEFT degrees
LT degrees

turns the turtle counterclockwise by the specified angle, measured in degrees (1/360 of a circle).

right

RIGHT degrees
RT degrees

turns the turtle clockwise by the specified angle, measured in degrees (1/360 of a circle).

setxy

SETXY xcor ycor

moves the turtle to an absolute screen position. The two arguments are numbers, the X and Y coordinates.

setx

SETX xcor

moves the turtle horizontally from its old position to a new absolute horizontal coordinate. The argument is the new X coordinate.

sety

SETY ycor

moves the turtle vertically from its old position to a new absolute vertical coordinate. The argument is the new Y coordinate.

home

HOME

moves the turtle to the center of the screen. Equivalent to SETXY 0 0.

setheading

SETHEADING degrees
SETH degrees

turns the turtle to a new absolute heading. The argument is a number, the heading in degrees clockwise from the positive Y axis.

Turtle Motion Queries

xcor

XCOR

outputs a number, the turtle's X coordinate.

ycor

YCOR

outputs a number, the turtle's Y coordinate.

heading

HEADING

outputs a number, the turtle's heading in degrees.

towards

TOWARDS xpos ypos

outputs a number, the heading at which the turtle should be facing so that it would point from its current position to the position given as the argument.

Turtle and Window Control

showturtle

SHOWTURTLE
ST

makes the turtle visible.

hideturtle

HIDETURTLE
HT

makes the turtle invisible. It's a good idea to do this while you're in the middle of a complicated drawing, because hiding the turtle speeds up the drawing substantially.

clean

CLEAN

erases all lines that the turtle has drawn on the graphics window. The turtle's state (position, heading, pen mode, etc.) is not changed.

clearscreen

CLEARSCREEN
CS

erases the graphics window and sends the turtle to its initial position and heading. Like HOME and CLEAN together.

See section home

Turtle and Window Queries

shownp

SHOWNP
SHOWN?

outputs TRUE if the turtle is shown (visible), FALSE if the turtle is hidden. See SHOWTURTLE and HIDETURTLE.

See section showturtle ; section hideturtle

Pen and Background Control

The turtle carries a pen that can draw pictures. At any time the pen can be UP (in which case moving the turtle does not change what's on the graphics screen) or DOWN (in which case the turtle leaves a trace). If the pen is down, it can operate in one of three modes: PAINT (so that it draws lines when the turtle moves), ERASE (so that it erases any lines that might have been drawn on or through that path earlier), or REVERSE (so that it inverts the status of each point along the turtle's path).

pendown

PENDOWN
PD

sets the pen's position to DOWN, without changing its mode.

penup

PENUP
PU

sets the pen's position to UP, without changing its mode.

penpaint

PENPAINT
PPT

sets the pen's position to DOWN and mode to PAINT.

penerase

PENERASE
PE

sets the pen's position to DOWN and mode to ERASE.

See section erase

penreverse

PENREVERSE
PX

sets the pen's position to DOWN and mode to REVERSE. (This may interact in hardware-dependent ways with use of color.)

See section reverse

Pen Queries

pendownp

PENDOWNP
PENDOWN?

outputs TRUE if the pen is down, FALSE if it's up.


Workspace Management

Procedure Definition

to

TO procname :input1 :input2 ...			(special form)

command. Begins a procedure definition. The procedure will be named procname and there must not already be a procedure by that name. The inputs will be called input1 etc. Any number of inputs are allowed, including none. Names of procedures and inputs are case-insensitive.

Unlike every other Logo procedure, TO takes as its inputs the names of arguments that will be passed to the procedure.

This version of Logo also allows a variable numbers of inputs to a procedure.  After all the required inputs are specified, there can be zero or more optional inputs, represented by the following notation:

[:inputname default.value.expression]

In this version of logo, the "main" procedure - the first procedure in the file and the one whose name matches the filename - handles inputs specially.  When the program is run, the user will be prompted for the values of these inputs via a dialog with text entry boxes.  These boxes will be blank for normal inputs, or pre-filled with the default values for inputs for inputs specified with the optional input syntax.  See the example programs included with this distribution for examples.

Procedures cannot return values; however, the can pass values to to their caller via global variables such as in this example:

to proc1
    proc2
    fd :output
end

to proc2
    make :output 10
end

Variable Definition

make

MAKE :varname value

command. Assigns the value value to the variable named varname, which must be a word. Variable names are case-insensitive. If a variable with the same name already exists, the value of that variable is changed. If not, a new global variable is created.

Not that the syntax here differs from most other Logo implementations.  For the sake of simplicity, the variable name to store the value to should be preceded by a colon, as with everywhere else a variable name is specified.

local

LOCAL :varname
LOCAL :varname1 :varname2 ...

command. Accepts as inputs one or more words, or a list of words. A variable is created for each of these words, with that word as its name. The variables are local to the currently running procedure. Logo variables follow dynamic scope rules; a variable that is local to a procedure is available to any subprocedure invoked by that procedure. The variables created by LOCAL have no initial value; they must be assigned a value (e.g., with MAKE) before the procedure attempts to read their value.

Local variables are useful because the memory they use is freed as soon as a function is completed.  Global variables, on the other hand, will reserve their memory until the program has finished executing.

See section make

Workspace Predicates

procedurep

PROCEDUREP name
PROCEDURE? name

outputs TRUE if the input is the name of a procedure.

primitivep

PRIMITIVEP name
PRIMITIVE? name

outputs TRUE if the input is the name of a primitive procedure (one built into Logo). Note that some of the procedures described in this document are library procedures, not primitives.

definedp

DEFINEDP name
DEFINED? name

outputs TRUE if the input is the name of a user-defined procedure, including a library procedure. (However, Logo does not know about a library procedure until that procedure has been invoked.)

namep

NAMEP name
NAME? name

outputs TRUE if the input is the name of a variable.


Control Structures

Control

repeat

REPEAT num [ instructionlist ]

command. Runs the instructionlist repeatedly, num times.

repcount

REPCOUNT

outputs the repetition count of the innermost current REPEAT, starting from 1. If no REPEAT is active, outputs --1.

if

IF condition [ instructionlist ]

command. If the first input has the value TRUE, then IF runs the second input. If the first input has the value FALSE, then IF does nothing. It is an error if the first input is not either TRUE or FALSE.

ifelse

IFELSE condition [ instructionlist1 ] [ instructionlist2 ]

command or operation. If the first input has the value TRUE, then IFELSE runs the second input. If the first input has the value FALSE, then IFELSE runs the third input.

test

TEST condition

command. Remembers its input, which must be TRUE or FALSE, for use by later IFTRUE or IFFALSE instructions. The effect of TEST is local to the procedure in which it is used; any corresponding IFTRUE or IFFALSE must be in the same procedure or a subprocedure.

See section iffalse

iftrue

IFTRUE [ instructionlist ]
IFT [ instructionlist ]

command. Runs its input if the most recent TEST instruction had a TRUE input. The TEST must have been in the same procedure or a superprocedure.

iffalse

IFFALSE [ instructionlist ]
IFF [ instructionlist ]

command. Runs its input if the most recent TEST instruction had a FALSE input. The TEST must have been in the same procedure or a superprocedure.

See section test

stop

STOP

command. Ends the running of the procedure in which it appears. Control is returned to the context in which that procedure was invoked.

pause

PAUSE

command or operation.  Pauses until the user presses a key.  Note that this function works differently here than in many other implementations of Logo.

wait

WAIT time

command. Delays further execution for time 20ths of a second. 

for

FOR [ :varname start end step ] [ instructionlist ]

command. The first input must be a list containing three or four members: (1) a variable name, which will be used as the name of a local variable; (2) a number, the starting value of the variable; (3) a a number, the limit value of the variable; (4) an optional number that will be step size. If the fourth member is missing, the step size will be 1 or -1 depending on whether the limit value is greater than or less than the starting value, respectively.

The second input is an instructionlist. The effect of FOR is to run that instructionlist repeatedly, assigning a new value to the control variable (the one named by the first member of the forcontrol list) each time. First the starting value is assigned to the control variable. Then the value is compared to the limit value. FOR is complete when the sign of (current-limit) is the same as the sign of the step size. (If no explicit step size is provided, the instructionlist is always run at least once. An explicit step size can lead to a zero-trip FOR, e.g., FOR [I 1 0 1] ...). Otherwise, the instructionlist is run, then the step is added to the current value of the control variable and FOR returns to the comparison step.

do.while

DO.WHILE [ instructionlist ] condition

command. Repeatedly evaluates the instructionlist as long as the evaluated tfexpression remains TRUE. Evaluates the first input first, so the instructionlist is always run at least once. The tfexpression must be an expressionlist whose value when evaluated is TRUE or FALSE.

while

WHILE condition { instructionlist ]

command. Repeatedly evaluates the instructionlist as long as the evaluated tfexpression remains TRUE. Evaluates the first input first, so the instructionlist may never be run at all. The tfexpression must be an expressionlist whose value when evaluated is TRUE or FALSE.

do.until

DO.UNTIL [ instructionlist ] condition

command. Repeatedly evaluates the instructionlist as long as the evaluated tfexpression remains FALSE. Evaluates the first input first, so the instructionlist is always run at least once. The tfexpression must be an expressionlist whose value when evaluated is TRUE or FALSE.

until

UNTIL condition [ instructionlist ]

command. Repeatedly evaluates the instructionlist as long as the evaluated tfexpression remains FALSE. Evaluates the first input first, so the instructionlist may never be run at all. The tfexpression must be an expressionlist whose value when evaluated is TRUE or FALSE.