Lists in LOGO are used to store data collections and as executable code blocks.
Collection. Elements of a list can have any type; different data types can be mixed in a single list.
Declaration of a constant list is following:
[a b c 1 2]
(elements are separated with white spaces; all elements are recognized as words; brackets
used inside the list are recognized as nested lists and arrays).
Size of a list can be modified by adding or removing elements from the beginning or the end of the list (see instructions:
queue, dequeue, push, pop).
Queues and stacks can be implemented in this way. The prefered method of sequential access to elements is
Outermost elements can be accessed with instructions
and indexing operator (
,) allow to read elements at any position, however they are expensive
(array is prefered for efficient random access to elements).
Elements in lists are immutable. Elements cannot be modified e.g. with
make "lis [a b [c]]
queue :lis 123
print dequeue :lis
[a b [c]]
[a b [c] 123]
[b [c] 123]
Source code block. Many instructions in LOGO use lists of instructions as arguments e.g. loops and
conditional statements. If such a list is provided as a constant in the code, then its content is compiled
together with the whole program.
make "x 0
repeat 5 [make "x :x + repcount print :x]
Output (sum of 1, ..., iteration number is calculated on each iteration):
Code block can be created also dynamically, during the program execution. In such case code will be compiled
before it is executed for the first time. If the list with code block is modified then the code is recompiled
make "fn [sqrt exp log]
foreach "n :fn (list "print :n 2)
Consecutive iterations of the
foreach loop in the above example are
performing following operations:
print sqrt 2
print exp 2
print log 2
Operations on collections:
queue, dequeue, push, pop
first, butfirst, last, butlast
count, emptyp, listp
Table of Content