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.

  1. Data Types
  2. Data Structure Primitives
  3. Communication
  4. Arithmetic
  5. Logical Operations
  6. Graphics
  7. Workspace Management
  8. Control Structures

Types

"word
'word
number
Word (terminated by whitespace)
show "hello
show 12.34
:variable
Input definition/variable reference
show :name
[ word ... ]
List of words or lists, whitespace separated
show [1 2 3]
{ word ... }
{ word ... }@origin
Array of words whitespace separated
show {1 2 3}
( expression )
Parenthesis can be used to group expressions
show ( 1 + 2 ) * 3
procedure input ...
Call procedure with default number of inputs
show "hello
( procedure input ... )
Call procedure with an arbitrary number of inputs
(show "hello :name)

2. Data Structure Primitives

2.1 Constructors

word expr expr
(word expr ...)
Concatenate two (or more) words into one word
show (word "a "b "c)
list thing1 thing2
(list thing1 thing2 ...)
Create a new list from the inputs
show (list 1+2 2+3 3+4)
array size
(array size origin)
Create a new array. The default origin is 1.
show array 10
listtoarray list
(listtoarray list origin)
Create a new array populated by members of a list
show listtoarray [ 1 3 5 7 ]
arraytolist array
Create a new list populated by members of a array
show arraytolist { 2 4 6 8 }
sentence thing1 thing2
(sentence thing1 thing2 ...)
se thing1 thing2
(se thing1 thing2 ...)
Create a new list from the inputs (if non-lists) or members of the inputs (if lists)
show sentence [1 2 3] [and so on]
fput thing list
lput thing list
Outputs list, but with thing added as a new first/last item
show fput 0 [ 1 2 3 ]
show lput 4 [ 1 2 3 ]
combine thing1 thing2
If thing2 is a word, like word; otherwise, like fput
show combine "a [b c]
reverse list
Outputs a list with the items in reverse order
show reverse [ 1 2 3 ]
gensym
Outputs a unique string, e.g. G1, G2, etc.
show gensym

2.2 Data Selectors

first list
last list
Outputs the first or last item from the list, respectively
show first [ 1 2 3 ]
show last [ 1 2 3 ]
butfirst list
bf list
butlast list
bl list
Outputs the list, except for the first/last item
show butfirst [ 1 2 3 ]
show butlast [ 1 2 3 ]
firsts listoflists
Outputs a list of the first item of each sublist
show firsts [ [1 2 3] [a b c] ]
butfirsts listoflists
bfs listoflists
Outputs a list of sublists without the first item
show butfirsts [ [ 1 2 3 ] [ a b c ] ]
pick list
Outputs one item from a list, at random
show pick [ 1 2 3 ]
item index thing
Outputs the indexth item of the list or array
show item 2 [ 1 2 3 ]
setitem index array value
Sets the indexth item of the array to value
make "a { 1 2 3 } setitem 2 :a "x show :a
remove thing list
Outputs the list with any occurences of thing removed
show remove "b [ a b c ]
remdup list
Outputs the list with duplicates removed
show remdup [ 1 2 3 2 3 4 3 4 5 ]

2.3 Data Mutators

push stackname thing
pop stackname
Push to/pop from a stack i.e. list variable. Stacks grow from the front.
make "s [ 2 1 ] push "s 3 show :s show pop "s
queue stackname thing
dequeue stackname
Add/remove from a queue i.e. list variable, Queues grow from the end.
make "q [ 1 2 ] queue "q 3 show :q show dequeue "q

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.
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).
emptyp expr
empty? expr
Test if thing is an empty list or empty string.
beforep thing1 thing2
before? thing1 thing2
Test string collation order.
memberp thing list
member? thing list
Test if thing is equal to any member of list.
substringp thing1 thing2
substring? thing1 thing2
Test if thing1 is a substring of thing2.

2.5 Queries

count thing
Outputs length of a list or number of characters in a string
show count [ 1 2 3 ]
show count "hello
ascii expr
Outputs ASCII (actually, Unicode) code point for first character of string
show ascii "abc
char expr
Outputs Unicode character at specified code point
show char 97
uppercase expr
lowercase expr
Outputs string converted to upper/lowercase
show uppercase "abc
show lowercase "ABC

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.
print "hello
type thing
(type thing1 thing2 ...)
Like print but with no trailing newline.
type "hel type "lo
show thing
(show thing1 thing2 ...)
Like print but with square brackets around list inputs.
show "hello

3.2 Receivers

readword
(readword promptstr)
Prompt the user for a line of input. The result (including spaces) is the single word output.
show readword
make "name (readword [What is your name?]) show :name

3.4 Terminal Access

cleartext
ct
Clear the text screen.

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
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
show iseq 1 10
rseq first last count
Outputs a list of count numbers from first to last, inclusive
show rseq 1 9 5

4.2 Numeric Predicates

greaterp expr expr
greater? expr expr
expr > expr
greaterequalp expr expr
greaterequal? expr expr
expr >= expr
lessp expr expr
less? expr expr
expr <= expr
lessequalp expr expr
lessequal? expr expr
expr <= expr
Greater than, greater than or equal to, less than, less than or equal to, respectively. Inputs are numbers or numeric expressions, output is 1 (true) or 0 (false).

4.3 Random Numbers

random expr
Outputs a random number from 0 through one less than expr
rerandom
(rerandom expr)
Reseeds the random number generator, either to a fixed value or the specified seed.

4.4 Print Formatting

form expr width precision
Returns a formatted string with the result of a numeric expression with precision decimal places and padded on the left with spaces (if necessary) to be at least width characters long.
show form 1/3 10 3

4.5 Bitwise Operations

bitand expr expr
(bitand expr ...)
bitor expr expr
(bitor expr ...)
bitxor expr expr
(bitxor expr ...)
bitnot expr
Bitwise and, or, exclusive-or, and not, respectively.
ashift expr bitcount
Arithmetic bit shift. If bitcount is negative, shifts to the right, preserving sign.
lshift expr bitcount
Logical bit shift. If bitcount is negative, shifts to the right, zero-filling.

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
fd 100
back expr
bk expr
Move turtle backward expr pixels
bk 100
left expr
lt expr
Rotate expr degrees counterclockwise
lt 90
right expr
rt expr
Rotate expr degrees clockwise
rt 90
setpos [ expr expr ]
setxy expr expr
setx expr
sety expr
Move turtle to the specified location
setxy -100 100
setheading expr
seth expr
Rotate the turtle to the specified heading
seth 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.
arc 180 100

6.2 Turtle Motion Queries

pos
xcor
ycor
Outputs the current turtle position as [ x y ], x or y respectively
show pos
heading
Outputs the current turtle heading
show heading
towards [ expr expr ]
Outputs the heading towards the specified [ x y ] coordinates
show towards [ 0 0 ]

6.3 Turtle and Window Control

showturtle
st
Show the turtle
hideturtle
ht
Hide the turtle
clean
Clear the drawing area
clearscreen
cs
Same as clean and home together
wrap
If the turtle moves off the edge of the screen it will continue on the other side. (default)
window
The turtle can move past the edges of the screen, unbounded.
fence
The turtle attempts to move past the edge of the screen it will stop.
fill
Does a paint bucket flood fill at the turtle's position.
arc 360 100 fill
filled fillcolor [ statements ... ]
Execute statements without drawing but keeping track of turtle movements. When complete, fill the region traced by the turtle with fillcolor and outline the region with the current pen style.
filled "red [ repeat 5 [ fd 100 rt 144 ] ]
label expr
Draw a word (same logic as print) on the graphics display at the turtle location
repeat 8 [ label "Logo rt 45 ]
setlabelheight expr
Set the height for text drawn by label, in pixels
setlabelheight 100 label "Logo

6.4 Turtle and Window Queries

shownp
shown?
Outputs 1 if the turtle is shown, 0 if the turtle is hidden
turtlemode
Outputs WRAP, WINDOW or FENCE
labelsize
Outputs the height of text drawn by label, in pixels

6.5 Pen and Background Control

pendown
pd
Turtle resumes leaving a trail
penup
pu
Turtle stops leaving a trail
penpaint
penerase
penreverse
Change the turtle drawing mode - paint (the default) leaves a colored trail, erase restores the background, reverse inverts the background.
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 3-input version, r/g/b values in 0...99.
The standard Logo colors are:
0: black 1: blue 2: green 3: cyan
4: red 5: magenta 6: yellow 7: white
8: brown 9: tan 10: green 11: aqua
12: salmon 13: purple 14: orange 15: gray
setpencolor 4
setpencolor "red
setpencolor "#ff0000
setpencolor [ 99 0 0 ]
setpensize expr
Set pen width in pixels. If expr is a list, the first member is used.

6.6 Pen Queries

pendownp
pendown?
Outputs 1 if the pen is down, 0 otherwise
penmode
Outputs PAINT, ERASE or REVERSE
pencolor
Outputs the current pen color. This will be a CSS color string, not necessarily the value passed in.
pensize
Outputs a two element list with the pen width and height (usually the same).

7. Workspace Management

7.1 Procedure Definition

to procname inputs ... statements ... end
Define a new named procedure with optional inputs
to star :n repeat 5 [ fd :n rt 144 ] end
def procname
Outputs the definition of a named procedure as a string
show def "star
copydef newname oldname
Copy a procedure. If a procedure newname already existed it will be overridden. Primitive procedures can't be overridden unless REDEFP is TRUE.
copydef "new "old

7.2 Variable Definition

make varname expr
Update a variable or define a new global variable. The variable name must be quoted
make "myvar 5
name expr varname
Like make but with the inputs reversed
name 5 "myvar
local varname
(local varname ...)
A subsequent make will create the variable(s) in the local scope instead of the global scope
local "myvar
localmake varname expr
Define a variable in the local scope (shortcut for local then make
localmake "myvar 5
thing varname
Outputs the value of variable. :foo is a shortcut for thing "foo
show thing "myvar
global varname
Reserve the variable at the global scope. This doesn't do anything useful.
global "myvar

7.3 Property Lists

pprop plistname propname value
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.

7.4 Workspace Predicates

Predicates return 1 (true) or 0 (false)

procedurep name
procedure? name
Test if there is a procedure with the given name.
primitivep name
primitive? name
Test if there is a built-in procedure with the given name.
definedp name
defined? name
Test if there is a user-defined procedure with the given name.
namep name
name? name
Test if there is a variable with the given name.
plistp name
plist? name
Test if there is a property list with the given name.

7.5 Workspace Queries

contents
Outputs a list with three members. The first is a list of user-defined procedure names. The second is a list of defined variables. The third is a list of non-empty property list names. Only non-buried procedures, variables, and property lists are included.
buried
Outputs a list with three members. The first is a list of user-defined procedure names The second is a list of defined variables. The third is a list of non-empty property list names. Only buried procedures, variables, and property lists are included.
procedures
Outputs a list of user-defined non-buried procedure names.
primitives
Outputs a list of primitive non-buried procedure names.
globals
Outputs a list of defined non-buried global variables.
names
Outputs a list with two members. The first is an empty list. The second is a list of defined non-buried variables.
plists
Outputs a list with three members. The first is an empty list. The second is an empty list. The third is a list of non-empty non-buried property list names.
namelist name
namelist namelist
Return a contents-style list with the given variable names.
pllist plname
pllist plnamelist
Return a contents-style list with the given property lists.

7.7 Workspace Control

erase contentslist
Takes a three member list, where the first is a list of user-defined procedure names to erase, the second is a list of defined variables to erase, the third is a list of property lists to erase. Primitive procedures can't be erased unless REDEFP is TRUE.
erase [ [myproc] [myvar] [] ]
erall
Erase all non-buried user-defined procedures, variables and property lists.
erps
Erase all non-buried user-defined procedures.
erns
Erase all non-buried variables.
erpls
Erase all non-buried property lists.
ern varname
ern varnamelist
Erase the named variable(s).
epl plname
epl plnamelist
Erase the named property list(s).
bury contentslist
Takes a three member list, where the first is a list of user-defined procedure names to bury, the second is a list of defined variables to bury, the third is a list of property lists to bury.
buryall
Bury all user-defined procedures, variables, and property lists.
unbury contentslist
Takes a three member list, where the first is a list of user-defined procedure names to unbury, the second is a list of defined variables to unbury, the third is a list of property lists to unbury.
unburyall
Unbury all user-defined procedures, variables, and property lists.
buriedp contentslist
buried? contentslist
Return 1 if the first named user-defined procedure, variable, or property list exists and is buried, 0 otherwise.

8. Control Structures

8.1 Control

run [ statements ... ]
Run the specified statements once
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
repeat 4 [ fd 100 rt 90 ]
forever [ statements ... ]
Repeat statements forever. Used inside a user-defined procedure that terminates with output, stop or bye
forever [ make "n random 100 show :n if :n == 0 [ bye ] ]
repcount
Outputs the current iteration number of the current repeat or forever
repeat 10 [ show repcount ]
if expr [ statements ... ]
Execute statements if the expression is non-zero
if 2 > 1 [ show "yep ]
ifelse expr [ statements ... ] [ statements ... ]
Execute first set of statements if the expression is non-zero, otherwise execute the second set
ifelse 1 > 2 [ show "yep ] [ show "nope ]
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.
test 1 > 2 iftrue [ show "yep ] iffalse [ show "nope ]
stop
End the running procedure with no output value
output expr
op expr
End the running procedure and output the specified value
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
make "q [ 1 2 3 ] ignore dequeue "q
for controllist [ statements ...]
Typical for loop. The controllist specifies three or four members: the local varname, start value, limit value, and optional step size.
for [ a 1 10 ] [ show :a ]
for [ a 0 20 2 ] [ show :a ]
do.while [ statements ...] expr
Runs the specified statements at least once, and repeats while the expression is non-zero (true).
do.while [ make "a random 10 show :a ] :a < 8
while expr [ statements ...]
Runs the specified statements only while the expression remains non-zero (true).
while (random 2) = 0 [ show "zero ] show "one
do.until [ statements ...] expr
Runs the specified statements at least once, and repeats while the expression is zero (false).
do.until [ make "a random 10 show :a ] :a < 8
until expr [ statements ...]
Runs the specified statements only while the expression remains zero (false).
until (random 2) = 0 [ show "one ] show "zero
case value [ clauses ... ]
For each clause in order: If the clause is of the form [ ELSE expr ] then expr is evaluated and returned. Otherwise, if the clause is of the form [ [ matches ] expr ] and value is a member of matches then expr is evaluated and returned.
show case :var [ [ ["a] "AAA ] [ ["b] "BBB ] [ else "other ] ]
cond [ clauses ... ]
For each clause in order: If the clause is of the form [ ELSE expr ] then expr is evaluated and returned. Otherwise, if the clause is of the form [ [ expr1 ] expr2 ] and expr1 evaluates to non-zero (true) then expr2 is evaluated and returned.
show cond [ [ [:var = 1] "one] [ [:var = 2] "two] [ else "other ] ]

8.2 Template-based Iteration

These higher-level procedures support only the named procedure form of template. The first input is the name of a procedure to call.

apply procname list
Call procname with the members of list as inputs
invoke procname input1
(invoke procname input1 ...)
Call procname with the specified inputs as inputs
invoke "show "hello
foreach procname list
call procname for each item in the list
foreach "show [1 2 3]
map procname list
Outputs a list composed of the results of calling procname for each item in the list
to double :n output :n * 2 end show map "double [1 2 3]
filter procname list
Outputs a list composed of the input list where procname called on the item returns non-zero (true)
to oddp :n output bitand :n 1 end show filter "oddp [ 1 2 3 4 5 ]
find procname list
Outputs the first item in list for which calling procname on it returns non-zero (true). If not found, the empty list is returned.
to oddp :n output bitand :n 1 end show find "oddp [ 2 8 4 7 10 9 ]
reduce procname list
(reduce procname list initial)
Call procname repeatedly with two inputs - the current value and the next list item. If initial is not specified, the first list element is used instead.
show reduce "sum [ 1 2 3 4 5 ]