Référence › Words and Lists — 77 commandes
apply
Entrée: template | inputlist
Sortie: 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
Entrée: number OR [number default]
Sortie: list
Creates a list with 'empty' items of the given number if only that number is provided, OR a list with default items of the given number if a list containing those values is provided. Once the list is created, you can replace the empty items using replace, for example
show replace 2 array 4 "frog
show array [4 frog]
butfirst
Aussi: bf
Entrée: word or list
Sortie: 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
Aussi: bl
Entrée: word or list
Sortie: 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
Entrée: list
Sortie: list
Returns a list containing only those elements that are not numbers.
show butnumbers [frog 12 cow 1234]
[frog cow]
butsearch
Entrée: searchmask (word) | list
Sortie: list
Returns the provided list minus the elements matched by the provided search mask. See search
show butsearch "*g [frog duck pig]
[duck]
caseinsensitive
Entrée: none
Sortie: none
Makes search, sort and comparisons case insensitive. These are case sensitive by default. See nocaseinsensitive
caseinsensitive
combine
Entrée: list1 list2
Sortie: list
Takes two lists and merges them at the same hierarchical level(s), combining common tree branches.
show combine [1 2 3] [4 5 6]
[1 2 3 4 5 6]
show combine [1 [2 3]] [4 [5 6]]
[1 [2 3 5 6] 4]
contains
Entrée: word number or list | list
Sortie: number
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
Entrée: word or list
Sortie: 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
Entrée: template | list
Sortie: 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]
cycle
Entrée: index (number) | word or list
Sortie: 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 cycle 5 [1 2 3 4 5 6 7 8 9]
[5 6 7 8 9 1 2 3 4]
show cycle 2 [pig duck frog]
[duck frog pig]
show cycle 4 "piglet
"letpig
empty
Entrée: none
Sortie: nothing
Returns nothing. Used to 'reset' a container or list item to nothing (undefined).
make "container empty
emptylist
Entrée: none
Sortie: none
Returns an empty list []
make "container emptylist
emptyp
Entrée: word or list item
Sortie: boolean
Returns true if the provided word or list item is empty (blank).
print emptyp "
true
english
Entrée: length (number) OR [searchmask] (list) OR [searchmask length] (list) OR [searchmask length1 length2] (list)
Sortie: list
Returns a list of english words based on the given parameters. The search pattern needs to be either quoted or piped ||
show english 12
show english [du*]
show english [du* 4]
show english [du* 4 8]
exchange
Entrée: index1 (number) | index2 (number) | word or list
Sortie: 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
Entrée: boolean function | word or list
Sortie: 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
Entrée: template [list] | inputs [list]
Sortie: 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
Entrée: word or list
Sortie: 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
Entrée: list
Sortie: 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
Entrée: number (number) | field (number) | precision (number)
Sortie: 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
Entrée: word | list
Sortie: list
Returns the specified list with the specified word inserted in front.
show fput "cow [pig goat]
[cow pig goat]
hardspace
Entrée: none
Sortie: "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
Entrée: list
Sortie: 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
Entrée: place (number) | word or list | item
Sortie: 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
Entrée: number or word | number, list or word
Sortie: 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
Aussi: it
Entrée: index OR [index1 index2 …] | list
Sortie: item
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. If a list is provided for the index parameter, item traverses the hierarchy of the provided data based on that list (see example).
show item 4 [dog cow pig frog]
frog
show item 2 [10 20 30]
20
show item [1 3] [[pig duck cow][frog dog sow]]
cow
iterate
Entrée: list expression
Sortie: 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
Entrée: list
Sortie: number
Returns the index of the first largest list item.
show largest [10 100 1000]
3
last
Entrée: word or list
Sortie: 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
Entrée: number | word or list
Sortie: 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
Entrée: none
Sortie: [
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
Entrée: word | word
Sortie: 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
Entrée: list
Sortie: 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
phrase
Entrée: word, long word or list | word, long word or list
Sortie: phrase
phrase allows you to create a long word from two (or more, if enclosed in parentheses) other long words, words, or lists.
make "phrase phrase "frog "duck
make "newword (phrase "frog "duck [1 2 3])
print :newword
frog duck 1 2 3
lowercase
Entrée: word
Sortie: word
Returns a lowercased version of the provided word.
show lowercase "FrOg
frog
show iterate [DUCK PIG FROG] [lowercase :item]
[duck pig frog]
lput
Entrée: word or number | list
Sortie: 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
Entrée: primitive (word) or list | list
Sortie: 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
Entrée: template (list) | input (list)
Sortie: 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
Entrée: search pattern (word) | word or list
Sortie: number
Returns the item number of the first matching search result instead of the result itself. See search, matchp
print match "*g [cat duck frog]
3
matches
Entrée: search pattern (word) | list
Sortie: 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]
member
Entrée: word or list
Sortie: 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
Entrée: none
Sortie: none
Makes search, sort and comparisons case sensitive. See caseinsensitive
nocaseinsensitive
number
Entrée: word
Sortie: 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
Entrée: list
Sortie: list
Returns a list containing only those elements that are numbers.
show numbers [12 pig 134 cow]
12 134
order
Entrée: word number or list
Sortie: 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
Entrée: phrase
Sortie: 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
Aussi: pk
Entrée: list
Sortie: item
Returns a random item from the provided list.
show pick [dog cow sheep]
sheep
setbackgroundcolor pick [1 4 5]
picked
Entrée: none
Sortie: number
Returns the item number of the last list item selected using pick in the current scope, or 0 if nothing has yet been picked.
show picked
range
Entrée: [startnumber endnumber (step)] (list)
Sortie: 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
Entrée: operation (word) | input (word or list)
Sortie: 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
Entrée: index (number) | word or list
Sortie: 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
Entrée: index list value
Sortie: list
Replaces the item at the specified index in the provided list with the provided value.
make "dogs replace 3 [doberman pug siamese] "chihuahua
returnkey
Entrée: none
Sortie: char 13
Returns a return (enter) character. See spacebar
show returnkey
reverse
Entrée: word, number or list
Sortie: 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
Entrée: none
Sortie: ]
Returns a right bracket. Useful for times when turtleSpaces does not allow you to use a right bracket in isolation.
print rightbracket
]
search
Entrée: searchmask (word) | list
Sortie: 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
Entrée: word, list or number
Sortie: 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
Aussi: se
Entrée: word | word
Sortie: 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
Entrée: index (number) OR indexes [numbers]| container (word) | value
Sortie: 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. If a list of indexes is provided, traverses list hierarchy top to bottom and changes relevant item.
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
Entrée: list
Sortie: 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
Entrée: list
Sortie: 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
Entrée: list
Sortie: index (number)show
Returns the index of the numerically smallest item in the provided list.
show smallest [10 100 1000]
1
spacebar
Entrée: none
Sortie: space (char 32)
Returns character 32, a space. Useful for constructing phrases with spaces in them.
show (word "a spacebar "b)
subset
Entrée: word OR list | start (number) | length (number)
Sortie: word or list
Returns a subset of a word or list, based on the starting item and the number of items (length). See item, leading, trailing
show subset "steamboat 6 4
show subset [duck pig cow frog] 2 2
third
Entrée: word, list or number
Sortie: 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
Entrée: number | word or list
Sortie: 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
Entrée: list
Sortie: none
Returns only the unique elements of a list.
show unique [pig frog frog duck]
[pig frog duck]
uppercase
Entrée: word
Sortie: word
Converts word to UPPERCASE.
print uppercase "i\ like\ to\ shout!
I LIKE TO SHOUT!
without
Entrée: word | word or list
Sortie: 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
Entrée: word or list | word or list
Sortie: 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 phrase. 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
animations
Entrée: "model
Sortie: list
Returns a list of available animation names for the specified model. Returns an empty list if the model doesn't exist or has no animations.
show animations "bernie
bf
Entrée: word | list
Sortie: word | list
Short form of butfirst. Returns all but the first element of a word or list.
print bf "hello ; prints "ello"
print bf [1 2 3] ; prints [2 3]
bl
Entrée: word | list
Sortie: word | list
Short form of butlast. Returns all but the last element of a word or list.
print bl "hello ; prints "hell"
print bl [1 2 3] ; prints [1 2]
meshes
Entrée: "model
Sortie: list
Returns a list of mesh names in the specified model.
show meshes "bernie
trim
Entrée: "string
Sortie: word
Removes leading and trailing whitespace from a string and returns the trimmed string. This is useful for cleaning up user input or processing text data.
show trim " hello world
hello world
make "input " test
show trim :input
test