Logo Language Guide
Logo Language Guide
The section numbers are per the Berkeley Logo Reference Manual in Brian Harvey's Computer Science Logo Style
volume 2: Advanced Techniques for ease
of comparison.
array size
(array size origin)
Create a new array. The default origin is 1.
Example: show array 10
mdarray [dimensions ...]
(mdarray [dimensions ...] origin)
Create a new multi-dimensional array. The default origin is 1.
Example: show mdarray [2 2]
listtoarray list
(listtoarray list origin)
Create a new array populated by members of a list
Example: show listtoarray [ 1 3 5 7 ]
arraytolist array
Create a new list populated by members of a array
Example: show arraytolist { 2 4 6 8 }
combine thing1 thing2
If thing2 is a word, like word; otherwise, like fput
Example: show combine "a [b c]
reverse list
Outputs a list with the items in reverse order; if input is a word, reverses characters
Example: show reverse [ 1 2 3 ]
Example: show reverse "abc
gensym
Outputs a unique string, e.g. G1, G2, etc.
Example: show gensym
https://www.calormen.com/jslogo/language.html 2/14
9/23/21, 10:37 PM Logo Language Guide
2.4 Predicates
Predicates return 1 (true) or 0 (false)
wordp thing
word? thing
listp thing
list? thing
arrayp thing
array? thing
numberp thing
number? thing
Test if thing is a word, list, array, or number respectively.
emptyp expr
empty? expr
Test if thing is an empty list or empty string.
equalp expr expr
equal? expr expr
expr = expr
notequalp expr expr
notequal? expr expr
expr <> expr
Equality/inequality tests. Compares strings, numbers, or lists (equal if length and all members are equal).
https://www.calormen.com/jslogo/language.html 3/14
9/23/21, 10:37 PM Logo Language Guide
2.5 Queries
count thing
Outputs length of a list or number of characters in a string
Example: show count [ 1 2 3 ]
Example: show count "hello
ascii expr
Outputs ASCII (actually, Unicode) code point for first character of string
Example: show ascii "abc
char expr
Outputs Unicode character at specified code point
Example: show char 97
member thing list
Outputs the list (or word) from the first occurence of thing to the end, or empty list (or word)
Example: show member "a "banana
Example: show member 2 [1 2 3 4]
uppercase expr
lowercase expr
Outputs string converted to upper/lowercase
Example: show uppercase "abc
Example: show lowercase "ABC
standout expr
Outputs string with alphanumeric characters in bold
Example: show standout "ABCabc123
parse word
Outputs word parsed as a list.
Example: show parse "1+2
runparse word
Outputs word parsed as instructions.
Example: show runparse "1+2
3. Communication
3.1 Transmitters
print thing
pr thing
(print thing1 thing2 ...)
(pr thing1 thing2 ...)
Print inputs to the text screen, separated by spaces, and followed by a newline.
Square brackets are only put
around sublists.
Example: print "hello
type thing
(type thing1 thing2 ...)
Like print but with no trailing newline.
Example: type "hel type "lo
show thing
(show thing1 thing2 ...)
Like print but with square brackets around list inputs.
Example: show "hello
3.2 Receivers
readlist
(readlist promptstr)
https://www.calormen.com/jslogo/language.html 4/14
9/23/21, 10:37 PM Logo Language Guide
Prompt the user for a line of input. The result is a list of words.
Example: show readlist
Example: make "colors (readlist [Type some colors:]) show :colors
readword
(readword promptstr)
Prompt the user for a line of input. The result (including spaces) is the single word output.
Example: show readword
Example: make "name (readword [What is your name?]) show :name
4. Arithmetic
4.1 Numeric Operations
Inputs are numbers or numeric expressions, output is a number.
sum expr expr
(sum expr ...)
expr + expr
difference expr expr
expr - expr
product expr expr
(product expr ...)
expr * expr
quotient expr expr
(quotient expr)
expr / expr
power expr expr
expr ^ expr
Add, subtract, multiply, divide, and raise-to-the-power-of respectively.
A single input to quotient returns the
reciprocal.
remainder expr expr
expr % expr
modulo expr expr
Outputs the remainder (modulus). For remainder and %
the result has the same sign as the first input; for
modulo the
result has the same sign as a the second input.
minus expr
- expr
Unary minus sign must begin a top-level expression, follow an infix
operator, or have a leading space and no
trailing space.
abs num
Absolute value
int num
round num
Truncate or round a number, respectively.
sqrt expr
exp expr
log10 expr
ln expr
https://www.calormen.com/jslogo/language.html 5/14
9/23/21, 10:37 PM Logo Language Guide
Square root, e to the power of, common logarithm, and natural logarithm, respectively.
arctan expr
(arctan x y)
sin expr
cos expr
tan expr
The usual trig functions. Angles are in degrees.
radarctan expr
(radarctan x y)
radsin expr
radcos expr
radtan expr
The usual trig functions. Angles are in radians.
iseq first last
Outputs a list with integers from first to last, inclusive
Example: show iseq 1 10
rseq first last count
Outputs a list of count numbers from first to last, inclusive
Example: show rseq 1 9 5
https://www.calormen.com/jslogo/language.html 6/14
9/23/21, 10:37 PM Logo Language Guide
5. Logical Operations
true
Outputs 1
false
Outputs 0
and expr expr
(and expr ...)
or expr expr
(or expr ...)
xor expr expr
(xor expr ...)
not expr
Logical "and", "or", "exclusive-or", and "not", respectively.
Inputs are numbers or numeric expressions, output is
1 (true) or 0 (false).
6. Graphics
An introduction to Turtle Geometry.
6.1 Turtle Motion
forward expr
fd expr
Move turtle forward expr pixels
Example: fd 100
back expr
bk expr
Move turtle backward expr pixels
Example: bk 100
left expr
lt expr
Rotate expr degrees counterclockwise
Example: lt 90
right expr
rt expr
Rotate expr degrees clockwise
Example: rt 90
setpos [ expr expr ]
setxy expr expr
setx expr
sety expr
Move turtle to the specified location
Example: setpos [ 100 -100 ]
Example: setxy -100 100
setheading expr
seth expr
Rotate the turtle to the specified heading
Example: setheading 45
home
Moves the turtle to center, pointing upwards
arc angle radius
Without moving the turtle, draws an arc centered on the turtle, starting at the turtle's heading.
Example: arc 180 100
scrunch
Outputs the current graphics scaling factors
Example: show scrunch
https://www.calormen.com/jslogo/language.html 8/14
9/23/21, 10:37 PM Logo Language Guide
px
Change the turtle drawing mode -
paint (the default) leaves a colored trail,
erase restores the background,
reverse inverts the background.
Example: setpw 10 px repeat 5 [ fd 100 rt 144 ]
setpencolor logocolor
setpencolor csscolor
setpencolor [r g b]
Set pen/text color. Color can be a standard Logo color number (0-15), CSS color string (CSS color names or
#rrggbb), or in the list version, r/g/b values in 0...99.
The standard Logo colors are:
0
1
2
3
https://www.calormen.com/jslogo/language.html 9/14
9/23/21, 10:37 PM Logo Language Guide
7. Workspace Management
7.1 Procedure Definition
to procname inputs ... statements ... end
Define a new named procedure. Inputs can be:
Required: :a :b
Optional (with default values): [:c 5] [:d 7]
Rest (remaining inputs as a list): [:r]
Default number of inputs: 3
Set the property propname in the property list plistname to value value.
gprop plistname propname
Get the value of the property propname in the property list plistname, or the empty list if no such property.
remprop plistname propname
Remove the property propname in the property list plistname.
plist plistname
Return a list of properties in the property list plistname, alternating property name, property value.
8. Control Structures
8.1 Control
run [ statements ... ]
Run the specified statements once
Example: run [ fd 100 rt 90 ]
runresult [ statements ... ]
Run the specified statements once. If the statements return a value, the result is a
list with the value as a single
member. Otherwise, the result is an empty list.
repeat expr [ statements ... ]
Repeat statements expr times
Example: repeat 4 [ fd 100 rt 90 ]
forever [ statements ... ]
Repeat statements forever. Used inside a user-defined procedure
that terminates with output, stop or bye
Example: forever [ make "n random 100 show :n if :n == 0 [ bye ] ]
repcount
#
Outputs the current iteration number of the current repeat or forever
Example: repeat 10 [ show repcount ]
Example: repeat 10 [ show # ]
if expr [ statements ... ]
if [expr] [ statements ... ]
Execute statements if the expression is non-zero
Example: if 2 > 1 [ show "yep ]
ifelse expr [ statements ... ] [ statements ... ]
ifelse [expr] [ statements ... ] [ statements ... ]
Execute first set of statements if the expression is non-zero, otherwise execute the second set
Example: ifelse 1 > 2 [ show "yep ] [ show "nope ]
test expr
test [expr]
Test the specified expression, save the result in the local scope for subsequent use by iftrue or iffalse
iftrue [ statements ...]
ift [ statements ...]
iffalse [ statements ...]
iff [ statements ...]
Run the statements if the result of the last local test was non-zero (true) or zero (false) respectively.
Example: test 1 > 2 iftrue [ show "yep ] iffalse [ show "nope ]
https://www.calormen.com/jslogo/language.html 12/14
9/23/21, 10:37 PM Logo Language Guide
stop
End the running procedure with no output value.
output expr
op expr
End the running procedure and output the specified value.
catch tag instructionlist
Run instructions, but if an error with matching tag is thrown, return the thrown value (if any).
Use "ERROR to
catch errors from regular procedures.
Example: catch "t [ show "before throw "t show "after ]
Example: catch "error [ show 1 / 0 ] show error
throw tag
(throw tag value)
Throw an error with the given tag which may be caught. An optional return value can be passed.
Example: show catch "t [ show "hello (throw "t "world) ]
error
Outputs a list describing the last error caught:
an error number, an error message message, and the procedure
name where the error occurred.
Example: catch "error [ show 1 / 0 ] show error
wait time
Pauses execution. time is in 60ths of a second.
bye
Terminate the program
.maybeoutput expr
Like output if expr returns a value, like stop otherwise
ignore expr
Evaluate and ignore results of the expression
Example: make "q [ 1 2 3 ] ignore dequeue "q
` list
Outputs the list with substitutions:
https://www.calormen.com/jslogo/language.html 13/14
9/23/21, 10:37 PM Logo Language Guide
https://www.calormen.com/jslogo/language.html 14/14