libs/helpers-lists.nls

Helper functions to handle lists and sets.

Summary
libs/helpers-lists.nlsHelper functions to handle lists and sets.
prefix-list-itemsAdds the given string as prefix to all list items
postfix-list-itemsAdds the given string as postfix to all list items
createListReports a list with the same number of elements as the given base list (alternatively the number may be given), each item has the given value.
risingListGives a list of rising values starting from 0
intersect-setsCalculates the intersection of sets (for example sets of technologies.)
intersect-listsCalculates the intersection of lists (for example lists containing technology->technology-names.)
intersect-technology-sets-by-nameCalculates the intersection of a set of technologies and a list of technology->technology-names by using the names as matching parameter.
change-all-but-first-elementChanges all list elements execpt the first
read-list-from-stringReads all items of a list from a string
append-to-listAppends the given string and value-list to the given list
add-booleanAdds the given boolean to each element of the given list

prefix-list-items

to-report prefix-list-items [li pre]

Adds the given string as prefix to all list items

Parameters

lilist
prestring, prefix to be added

Returns

listaltered list

postfix-list-items

to-report postfix-list-items [li post]

Adds the given string as postfix to all list items

Parameters

lilist
poststring, postfix to be added

Returns

listaltered list

createList

to-report createList [input value]

Reports a list with the same number of elements as the given base list (alternatively the number may be given), each item has the given value.

Parameters

inputlist or number
valuevalue for each element

Returns

listlist of input length (by length of list or by number) with each element set to value

risingList

to-report risingList [numberItems]

Gives a list of rising values starting from 0

Parameters

numberItemslength of list

Returns

listlist of length numberItems with rising values from 0 on

intersect-sets

to-report intersect-sets [set-a set-b]

Calculates the intersection of sets (for example sets of technologies.)

Parameters

set-aAgentset that shall be intersected with set-b
set-bAgentset of the same type (agents, nodes, edges, technologies etc) as set-a.

Returns

agentsetThe set of elements that are part of both input sets.

intersect-lists

to-report intersect-lists [list-a list-b]

Calculates the intersection of lists (for example lists containing technology->technology-names.)

Parameters

list-alist of strings
list-blist of strings

Returns

list of stringsThe list of strings contains that strings from the input which are part of both lists.

intersect-technology-sets-by-name

to-report intersect-technology-sets-by-name [technology-set technology-name-list]

Calculates the intersection of a set of technologies and a list of technology->technology-names by using the names as matching parameter.

Parameters

technology-setagentset of technologies
technology-name-listlist of strings, technology.technology-names

Returns

agentset of <technologies>The agentset of technologies that is represented in both parameters (as technology or by technology.technology-name).

change-all-but-first-element

to-report change-all-but-first-element [old-list change-list]

Changes all list elements execpt the first

Parameters

old-listlist to change (first element will be preserved)
change-listlist of new values (first element will be ignored)

Returns

listlist of new values execpt for first element

read-list-from-string

to-report read-list-from-string [content]

Reads all items of a list from a string

Parameters

contentstring with lists elements to be read

Returns

listnetlogo style list

append-to-list

to-report append-to-list [my-list item-type value-list]

Appends the given string and value-list to the given list

Parameters

my-listlist to be altered
item-typestring to be used as key
value-listsource-list, to be addes element-wise as content to my-list

Returns

listmy-list, supplemented by item-type and value-list

add-boolean

to-report add-boolean [my-list my-boolean]

Adds the given boolean to each element of the given list

Parameters

my-listthe list to be altered
my-booleanthe boolean value to be added

Returns

nested ordered listsecond element of each sub-list is the boolean given as input.
to-report prefix-list-items [li pre]
Adds the given string as prefix to all list items
to-report postfix-list-items [li post]
Adds the given string as postfix to all list items
to-report createList [input value]
Reports a list with the same number of elements as the given base list (alternatively the number may be given), each item has the given value.
to-report risingList [numberItems]
Gives a list of rising values starting from 0
to-report intersect-sets [set-a set-b]
Calculates the intersection of sets (for example sets of technologies.)
Hold the technology objects.
to-report intersect-lists [list-a list-b]
Calculates the intersection of lists (for example lists containing technology->technology-names.)
the technologie’s name.
to-report intersect-technology-sets-by-name [technology-set technology-name-list]
Calculates the intersection of a set of technologies and a list of technology->technology-names by using the names as matching parameter.
to-report change-all-but-first-element [old-list change-list]
Changes all list elements execpt the first
to-report read-list-from-string [content]
Reads all items of a list from a string
to-report append-to-list [my-list item-type value-list]
Appends the given string and value-list to the given list
to-report add-boolean [my-list my-boolean]
Adds the given boolean to each element of the given list
Hold the agents.
Hold the nodes.
Hold the edges.
Holds the technologies
Close