words and lists


apply

Takes:   template | inputlist

Returns:   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

Takes:   number

Returns:   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

Takes:   word or list

Returns:   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

Takes:   word or list

Returns:   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

Takes:   list

Returns:   list

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

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


butsearch

Takes:   searchmask (word) | list

Returns:   list

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

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


caseinsensitive

Takes:   none

Returns:   none

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

caseinsensitive


contains

Takes:   word number or list | list

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

show contains “frog [duck frog pig]

2


count

Takes:   word or list

Returns:   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

Takes:   template | list

Returns:   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

Takes:   none

Returns:   nothing

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

make "container empty


emptylist

Takes:   none

Returns:   none

Returns an empty list []

make "container emptylist


emptyp

Takes:   word or list item

Returns:   boolean

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

print emptyp "
true


english

Takes:   length (number) OR [searchmask] (list) OR [searchmask length] (list) OR [searchmask length1 length2] (list)

Returns:   list

Returns a list of english words based on the given parameters.

show english 12
show english [du*]
show english [du* 4]
show english [du* 4 8]


exchange

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

Returns:   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

Takes:   boolean function | word or list

Returns:   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

Takes:   template [list] | inputs [list]

Returns:   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

Takes:   word or list

Returns:   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

Takes:   list

Returns:   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

Takes:   number (number) | field (number) | precision (number)

Returns:   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

Takes:   word | list

Returns:   list

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

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


hardspace

Takes:   none

Returns:   “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

Takes:   list

Returns:   list

Returns a list of numbers indicating the order of provided list items were they to be ordered using the ORDER primitive. For example, the second item in the example list would be the first item in a sorted list, the third item the second and so forth.

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


insert

Takes:   place (number) | word or list | item

Returns:   word or list

Returns the specified word or list with the specified item inserted at the specified place. Compare with replace

show insert 3 [1 2 3 4 5] 6
[1 2 6 3 4 5]

show insert 4 "piggy "f
pigfgy

show insert 1 [cat dog] "mouse
[mouse cat dog]


instances

Takes:   number or word | number, list or word

Returns:   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

Takes:   index list

Returns:   Returns the individual list item indicated by the index number as a word or number. If a negative index is provided, item returns the item based on counting back from the end of the list. If the index is greater than the number of items in the list, item returns the item at the index of the remainder of dividing the index by the number of items in the list.

show item 4 [dog cow pig frog]

frog

show item 2 [10 20 30]
20

show item 4 [1 2]
2


iterate

Takes:   list expression

Returns:   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

Takes:   list

Returns:   number

Returns the index of the first largest list item.

show largest [10 100 1000]
3


last

Takes:   word or list

Returns:   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

Takes:   number | word or list

Returns:   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

Takes:   none

Returns:   [

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

Takes:   word | word

Returns:   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

Takes:   list

Returns:   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

Takes:   word, long word or list | word, long word or list

Returns:   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

Takes:   word

Returns:   word

Returns a lowercased version of the provided word.

show lowercase "FrOg
frog

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


lput

Takes:   word or number | list

Returns:   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

Takes:   primitive (word) or list | list

Returns:   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

Takes:   template (list) | input (list)

Returns:   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

Takes:   search pattern (word) | list

Returns:   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

Takes:   search pattern (word) | list

Returns:   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

boolean

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

Takes:   word or list

Returns:   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

Takes:   none

Returns:   none

Makes search, sort and comparisons case sensitive. See caseinsensitive

nocaseinsensitive


number

Takes:   word

Returns:   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

Takes:   list

Returns:   list

Returns a list containing only those elements that are numbers.

show numbers [12 pig 134 cow]
12 134


order

Takes:   word number or list

Returns:   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

Takes:   longword

Returns:   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

Takes:   list

Returns:   item

Returns a random item from the provided list.

show pick [dog cow sheep]
sheep

setbackgroundcolor pick [1 4 5]


range

Takes:   [startnumber endnumber (step)] (list)

Returns:   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

Takes:   operation (word) | input (word or list)

Returns:   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

Takes:   index (number) | word or list

Returns:   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

Takes:   index list value

Returns:   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

Takes:   word, number or list

Returns:   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

Takes:   none

Returns:   ]

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

print rightbracket
]


rotate

Takes:   index (number) | word or list

Returns:   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

Takes:   searchmask (word) | list

Returns:   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

Takes:   word, list or number

Returns:   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

Takes:   word | word

Returns:   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]


setitem

Takes:   index (number) | container (word) | value

Returns:   none

Replaces the character or item at the specified index in the container with the given value, depending on if the value stored in the container is a word or a list.

make "animals [pig duck cow]
setitem 3 "animals "frog
show :animals
[pig duck frog]

make "animal "cow
setitem 4 "animal "s
show :animal
sow


shortest

Takes:   list

Returns:   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

Takes:   list

Returns:   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

Takes:   list

Returns:   number

Returns the numerically smallest item in the provided list.

show smallest [10 100 1000]
1


spacebar

Takes:   none

Returns:   space (char 32)

Returns character 32, a space. Useful for constructing longwords with spaces in them.

show (word "a spacebar "b)


third

Takes:   word, list or number

Returns:   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

Takes:   number | word or list

Returns:   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

Takes:   list

Returns:   none

Returns only the unique elements of a list.

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


uppercase

Takes:   word

Returns:   word

Converts word to UPPERCASE.

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


without

Takes:   word | word or list

Returns:   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

Takes:   word or list | word or list

Returns:   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