words and lists


word

words and lists

none

none

A word is an atomic word of characters. Words can be declared in two ways: either by prefacing them with a double quote ” as in “word, which does not allow spaces in the word, as the space would break the word, or with pipes as in |long word|, which can contain spaces within them. Keep in mind that a long word is treated as an atomic (single) word, and as such if you attempt to use list primitives on a long word they will not work the way you might expect, as they will only see one item.

print "word
print |long word|


apply

words and lists

template | inputlist

output

Runs the “template,” filling its slots with the members of “inputlist.” The number of members in “inputlist” must be an acceptable number of slots for “template.” It is illegal to apply the primitive TO as a template, but anything else is okay. APPLY outputs what “template” outputs, if anything.

print apply [[x] :x+5] [5]
10


array

words and lists

number

list

Creates a list with ’empty’ items of the given number. Once the list is created, you can replace the empty items using replace, for example

show replace 2 array 4 "frog


butfirst bf

words and lists

word or list

word or list

Returns the provided word or list with all elements except the first. See butlast

show butfirst [dog pig cow]
[pig cow]

show butfirst "spot
pot


butlast bl

words and lists

word or list

word or list

Returns the provided word or list with all elements except the last. See butfirst

show butlast [dog pig cow]
[dog pig]

show butlast "spot
spo


butnumbers

words and lists

list

list

Returns a list containing only those elements that are not numbers.

show butnumbers [frog 12 cow 1234]
[frog cow]


butsearch

words and lists

searchmask (word) | list

list

Returns the provided list minus the elements matched by the provided search mask. See search

show butsearch "*g [frog duck pig]
[duck]


caseinsensitive

words and lists

none

none

Makes search, sort and comparisons case insensitive. These are case sensitive by default. See nocaseinsensitive

caseinsensitive


contains

words and lists

word or list | list

Returns the index of the first list item matched by the provided word or list. See containsp

show contains “frog [duck frog pig]

2


count

words and lists

word or list

number

Returns the number of characters or items in the provided word or list, respectively.

show count "frog
4

show count [pig duck frog]
3


crossmap

words and lists

template | list

list

outputs a list containing the results of template evaluations. Each data list contributes to a slot in the template; the number of slots is equal to the number of data list inputs. As a special case, if only one data list input is given, that list is taken as a list of data lists, and each of its members contributes values to a slot. CROSSMAP differs from MAP in that instead of taking members from the data inputs in parallel, it takes all possible combinations of members of data inputs, which need not be the same length.

show (crossmap [word ?1 ?2] [a b c] [1 2 3 4])
[a1 a2 a3 a4 b1 b2 b3 b4 c1 c2 c3 c4]


empty

words and lists

none

nothing

Returns nothing. Used to ‘reset’ a container or list item to nothing (undefined).

make "container empty


emptylist

words and lists

none

none

Returns an empty list []

make "container emptylist


emptyp

words and lists

word or list item

boolean

Returns true if the provided word or list item is empty (blank).

print emptyp "
true


exchange

words and lists

index1 (number) | index2 (number) | word or list

word or list

Exchanges the item at index1 in the given word or list with the item at index2.

show exchange 1 2 [pig cow]
[cow pig]

show exchange 1 5 "solar
"rolas


filter

words and lists

boolean function | word or list

word or list

Applies the provided boolean function to each character or list item in provided word or list.

print filter "consonantp "aardvark
rdvrk


find

words and lists

template [list] | inputs [list]

result

Find outputs the first constituent of the data input (the first member of a list, or the first character of a word) for which the value produced by evaluating the template with that constituent in its slot is TRUE. If there is no such constituent, the empty list is output.

In a template, the symbol ?REST represents the portion of the data input to the right of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then ?REST would be replaced by [C D E].

In a template, the symbol # represents the position in the data input of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then # would be replaced by 2.

to spellout :card
output (sentence (butlast :card) "of
(find [equalp last :card first ?]
[hearts spades diamonds clubs]))
end

print spellout "5d
5 of diamonds

print spellout "10h
10 of hearts


first

words and lists

word or list

word or list

Returns the first item or character in a list or word. See last.

print first "frog
f

print first [frog pig duck]
frog


flat

words and lists

list

list

Takes all words inside the provided list and flattens them to a single level, removing any internal hierarchy.

show flat [pig duck [cow frog [chicken sheep]]]
[pig duck cow frog chicken sheep]


form

words and lists

number (number) | field (number) | precision (number)

word

Form outputs the input number as a word inside the number of spaces indicated by field, with the number of digits after the decimal point indicated by precision. Spaces are added to the beginning of the word as necessary.

show form pi 10 2
3.14


fput

words and lists

word | list

list

Returns the specified list with the specified word inserted in front.

show fput "cow [pig goat]
[cow pig goat]


hardspace

words and lists

none

“hard space”

Returns a “hard space”, the space that exists at ascii code 160 as opposed to 32 (the standard space). This is needed if you want to use a space in a list or anywhere else the Logo parser might resolve a normal space to nothing.

show hardspace


index

words and lists

list

list

Returns a list of numbers indicating the order of provided list items were they to be ordered using the ORDER primitive.

show index [pig dog cow duck]
[3 2 4 1]


instances

words and lists

number or word | number, list or word

number

Returns the number of instances of the first parameter in the second parameter.

print instances 3 [1 2 3 3 4 5]
2

print instances "l "volleyball
4

pr instances 5 123552
2


item it

words and lists

index list

Returns the individual list item indicated by the index number as a word or number.

show item 4 [dog cow pig frog]

frog

show item 2 [10 20 30]
20


iterate

words and lists

list expression

list

Iterate is a functional version of foreach. It takes a list to be processed, and an expression to evaluate. In the expression, the item to be processed is represented by :item

print iterate [3 5 6] [:item * 3]
9 15 18


largest

words and lists

list

number

Returns the index of the first largest list item.

show largest [10 100 1000]
3


last

words and lists

word or list

word

Returns the last letter (if input is word) or word (if input is list) in the provided input.

print last "frog
g

print last [frog pig duck]
duck


leading

words and lists

number | word or list

word or list

Returns the specified number of leading items (characters or list items) in the provided word or list. See trailing

print leading 4 "teleporter
tele

show leading 2 [dog cat pig frog]
[dog cat]


leftbracket

words and lists

none

[

Returns a left square bracket. Useful for times when turtleSpaces won’t allow you to use an actual left bracket. See rightbracket

print "[
MISSING ]

print leftbracket
[


list

words and lists

word | word

list

Takes two words and returns a list. You can use more or less than two words if you surround the entire list primitive with round brackets, as in the example.

show list "frog "pig
[frog pig]

show (list "frog "pig "duck)
[frog pig duck]


longest

words and lists

list

number

Returns the item number of the first longest item in the list by number of characters or digits. See count

print longest [pig duck cow]
2

print longest [1000 100 10]
1


longword

words and lists

word, long word or list | word, long word or list

longword

Longword allows you to create a long word from two (or more, if enclosed in parentheses) other long words, words, or lists.

make "longword longword "frog "duck

make "newword (longword "frog "duck [1 2 3])
print :newword
frog duck 1 2 3


lowercase

words and lists

word

word

Returns a lowercased version of the provided word.

show lowercase "FrOg
frog

show iterate [DUCK PIG FROG] [lowercase :item]
[duck pig frog]


lput

words and lists

word or number | list

list

Adds the provided word or number to the provided list. See fput

show lput 40 [10 20 30]
[10 20 30 40]

show lput "pig [dog cow duck]
[dog cow duck pig]


map

words and lists

primitive (word) or list | list

list

MAP outputs a word or list, depending on the type of the data input, of the same length as that data input.(If more than one data input are given, the output is of the same type as data1.) Each member of the output is the result of evaluating the template list, filling the slots with the corresponding member(s) of the data input(s). (All data inputs must be the same length.) In the case of a word output, the results of the template evaluation must be words, and they are concatenated with WORD. if first parameter is “primitive, map passes iterations to the specified primitive and returns the results in a list. See examples

show map [? * ?] [2 3 4 5]
[4 9 16 25]

show map [(word ?1 ?2 ?1)] [[a b c] [d e f]]
[ada beb cfc]

show map "word [[a b c] [d e f]]
[ad be cf]


mapse

words and lists

template (list) | input (list)

result (list)

outputs a list formed by evaluating the template list repeatedly and concatenating the results using SENTENCE. That is, the members of the output are the members of the results of the evaluations. The output list might, therefore, be of a different length from that of the data input(s). (If the result of an evaluation is the empty list, it contributes nothing to the final output.) The data inputs may be words or lists.

In a template, the symbol ?REST represents the portion of the data input to the right of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then ?REST would be replaced by [C D E]. If multiple parallel slots are used, then (?REST 1) goes with ?1, etc.

In a template, the symbol # represents the position in the data input of the member currently being used as the ? slot-filler. That is, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then # would be replaced by 2.

make "numbers [zero one two three four five six seven eight nine]
show mapse [item ?+1 :numbers] 5789
[five seven eight nine]

show mapse [sentence (word "With ?) "You] [in out]
[Within You Without You]

show mapse [sentence ? "Warner] [Yakko Wakko Dot]
[Yakko Warner Wakko Warner Dot Warner]


match

words and lists

search pattern (word) | list

number

Returns the item number of the first matching search result instead of the result itself. See search

print match "*g [cat duck frog]
3


matches

words and lists

search pattern (word) | list

list

Returns a list of the item number(s) matching the search word instead of the results themselves. See search

print matches "*g [pig duck cat frog]
[1 4]

###

matchp

booleans

search pattern (word) | list

boolean

Returns true if doing a search of the provided list using the provided search word would return a result.

show matchp 10 [10 20 30]
true


member

words and lists

word or list

word or list

Member returns the part of the second parameter in which the first parameter is the first element.

show member "duck [pig duck frog]
[duck frog]

show member "du "pigduck
"duck


nocaseinsensitive

words and lists

none

none

Makes search, sort and comparisons case sensitive. See caseinsensitive

nocaseinsensitive


number

words and lists

word

number

Converts a word or list item into a number. Usually turtleSpaces will convert a word into a number automatically if the word is supplied to a numeric function, but there are cases such as comparison operators where you may need to convert the word to a number manually in order to ensure correct evaluation.

print number "20
20


numbers

words and lists

list

list

Returns a list containing only those elements that are numbers.

show numbers [12 pig 134 cow]
12 134


order

words and lists

word number or list

none

Returns the input in alphabetical and / or numeric order, numbers first.

show order "frog
fgor

show order 54321
12345

show order jq831md
138djmq

show order [pigeon duck goose chicken]
[chicken duck goose pigeon]


parse

words and lists

word

list

Outputs a list that is created from parsing the provided word. Useful for converting the output of readword into a list, or converting other ‘long words’ (words with spaces) into their component parts.

show parse |dog cat pig|
[dog cat pig]


pick pk

words and lists

list

item

Returns a random item from the provided list.

show pick [dog cow sheep]
sheep

setbackgroundcolor pick [1 4 5]


range

words and lists

[startnumber endnumber (step)] (list)

list

Returns a list containing a range of numbers starting with startnumber and incrementing by one until and including endnumber, unless endnumber is less than one away from the current number. If the optional step value is included, range will step by that value, without overshooting. For an alternate method, see sequence

show range [1 10]
[1 2 3 4 5 6 7 8 9 10]

show range [0.5 10.25]
[0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5]

show range [1 10 3]
[1 4 7 10]


reduce

words and lists

operation (word) | input (word or list)

output

invokes a combining function to join the members of an aggregate. Reduce takes two inputs. The first must be the name of a two-input operation; the second can be any word or list.

show reduce "word [C S L S]
CSLS

show reduce "sentence "UNICEF
[U N I C E F]


remove

words and lists

index (number) | word or list

word or list

Returns a word or list without the specified character or list item.

show remove 2 [pig duck frog]
[pig frog]

print remove 4 "frog
fro


replace

words and lists

index list value

list

Replaces the item at the specified index in the provided list with the provided value.

make "dogs replace 3 [doberman pug siamese] "chihuahua


reverse

words and lists

word, number or list

word, number or list

Reverses the order of the provided word, number or list.

print reverse 123
321

print reverse "duck
ckud

show reverse [pig duck frog cow]
[cow frog duck pig]


rightbracket

words and lists

none

]

Returns a right bracket. Useful for times when turtleSpaces does not allow you to use a right bracket in isolation.

print rightbracket
]


rotate

words and lists

index (number) | word or list

Makes index the first item in the output, followed by the remaining items after it in the input, then the items before it, starting with the first.

show rotate 5 [1 2 3 4 5 6 7 8 9]

[5 6 7 8 9 1 2 3 4]

show rotate 2 [pig duck frog]
[duck frog pig]

show rotate 4 "piglet
"letpig


search

words and lists

searchmask (word) | list

list

Returns any items in the provided list that match the provided search mask, which can contain asterisks * which ‘wildcard’ the start or the end of the search mask (and return results that match any characters trailing or leading the search mask) or question marks ? that wildcard a single character. For example, fr* would match both free and frog, while f?r would match for and far.

show search "fr* [frog fred duck]
[frog fred]


second

words and lists

word, list or number

letter, word, list or number

Returns the second item in a word, list or number. See also first, third

print second 345
4

print second [dog pig duck]
pig

print second "frog
r


sentence se

words and lists

word | word

list

Creates a list from the given words. If brackets are placed around the sentence primitive and its inputs, it can take one or as many inputs as required.

make "var sentence "duck "pig
(show sentence "duck "pig "cow)
[duck pig cow]


shortest

words and lists

list

number

Returns the item number of the first shortest item in the list by number of characters or digits. See count

print shortest [pig duck cow]
1

print shortest [1000 100 10]
3


shuffle

words and lists

list

list

Randomly re-orders contents of provided list.

show shuffle [1 2 3 4 5]
[3 1 5 4 2]

show shuffle [frog duck pig]
[pig frog duck]


smallest

words and lists

list

number

Returns the numerically smallest item in the provided list.

show smallest [10 100 1000]
1


third

words and lists

word, list or number

letter, word, list or number

Returns the third item in a word, list or number. Lists of three things (co-ordinates, vectors) are common in turtleSpaces and first, second, third are more elegant than item 1, item 2, item 3. If you want fourth, fifth etc, you can create your own procedures for them! That is the beauty of Logo. See also first, second

print third 345
5

print third [dog pig duck]
duck

print third "frog
o


trailing

words and lists

number | word or list

word or list

Returns the specified number of trailing (ending) items in the provided word or list. See leading

print trailing 4 "teleport
port

show trailing 2 [dog cat pig frog]
[pig frog]


unique

words and lists

list

none

Returns only the unique elements of a list.

show unique [pig frog frog duck]
[pig frog duck]


uppercase

words and lists

word

word

Converts word to UPPERCASE.

print uppercase "i\ like\ to\ shout!
I LIKE TO SHOUT!


without

words and lists

word | word or list

word or list

Removes all instances of the specified word in the specified word or list and returns the result.

show without "pig [dog cow pig]
[dog cow]

show without "pig "dogcowpig
"dogcow


word

words and lists

word or list | word or list

word

Combines its inputs into a single word, without spaces between them. word takes two inputs, unless enclosed in round brackets (). To combine multiple inputs into a word with spaces, see longword. To combine multiple inputs into a list, see sentence

show word "frog "duck
frogduck

show (word "one "two "three)
onetwothree

show (word [pig duck chicken])
pigduckchicken