Below you can find all functions included with Manglang. They are either built-in or implemented in the standard library.
For all container functions we specify how the time complexity depends on the number of elements N in the container. So an operation that is marked as O(1) takes the same time for small and large containers. An operation that is marked as O(N) takes twice as long for a container that is twice as big.
take!container returns a single item from the container. O(1).drop!container returns the container with a single item dropped from it. O(1).put!(item container) returns a new container with item added to the old container. For tables we have that put!((key value) table) sets the value corresponding to the key in the table and returns the table. For stacks and strings the original container is not mutated, but it is mutated for tables so that other references to it are effected as well! O(1).clear!container returns an empty container of the same type as the input. O(1).container!index can be used to get the item at the specified index. The container is interpreted as a function which takes an index as input and outputs an item. O(N).if container then ... else ... O(1).
These operations can be used as a base for building more container functions. The standard library does that and adds all the functions below.
fold!(binary_operation container init) is mainly used as an algorithmic building block to implement the other container functions. O(N).reverse!container returns a container with the items in the reverse order for stacks and string. For tables we just get a copy, since a table is always sorted by its keys. O(N).take!container returns a single item from the container. O(1).take_many!(n container) returns a new containers with n items taken from the input container. O(n).take_while!(predicate container) returns a new containers with items taken from the input container as long as the predicate says yes. O(N).take_until_item!(item container) returns a new containers with items taken from the input container until the query item is found. O(N).drop!container returns the container with a single item dropped from it. O(1).drop_many!(n container) returns the container with n items dropped from it. O(n).drop_while!(predicate container) returns the container with items dropped from it as long as the predicate says yes. O(N).drop_until_item!(item container) returns a container with items dropped until the query item is found. O(N).clear!container returns an empty container of the same type as the input. O(1).clear_item!(item container) returns a container with all occurances of the specified item removed. O(N).clear_if!(predicate container) returns a container without the items for which the predicate says yes. O(N).replace!(new_item container) returns a container where each item is replaced with new_item. O(N).replace_item!(old_item new_item container) returns a container with occurances of old_item replaced with new_item. O(N).replace_if!(predicate new_item container) returns a container where each item is replaced if the predicate says yes. O(N).count!container returns the number of items in the container. O(N).count!(item container) counts the number of occurances of an item in the container. O(N).count_if!(predicate container) counts the number of items for which the predicate says yes. O(N).take!container and drop!container and container!index, or using the following functions:
get0!container returns the item with index 0 in the container. O(1).get1!container returns the item with index 1 in the container. O(1).get2!container returns the item with index 2 in the container. O(1).get3!container returns the item with index 3 in the container. O(1).get4!container returns the item with index 4 in the container. O(1).get5!container returns the item with index 5 in the container. O(1).get6!container returns the item with index 6 in the container. O(1).get7!container returns the item with index 7 in the container. O(1).get8!container returns the item with index 8 in the container. O(1).get9!container returns the item with index 9 in the container. O(1).xs=map!(get0 points). Secondly, when using multiple indices to index containers of containers like scalar=get3!get2!matrix. Otherwise, the easiest option is container!index, which works well in most other situations.
make_stack!container copies the items in the container to a new stack. O(N).make_string!container copies the items in the container to a new string. O(N).make_table!container copies the items in the container to a new table. The container should contain tuples of (key value). O(N).merge_stack![c1 ... cn] concatenates a stack of containers into a single stack. O(N).merge_string![c1 ... cn] concatenates a stack of containers into a single string. O(N).merge_table![c1 ... cn] merges a stack of containers into a single table. O(N).map!(f container) returns a new container with the function f applied to each item in the input container. The type of the output container is the same as the type of the input container. O(N).map_stack!(f container) returns a stack with the function f applied to each item in the container. O(N).map_string!(f container) returns a string with the function f applied to each item in the container. O(N).map_table!(f container) returns a table with the function f applied to each item in the container. The function f should return a tuple (key value). O(N).range!n returns the stack [0 1 2 ... n-1]. O(n).enumerate![7 9 4] returns the stack of tuples [(0 7) (1 9) (2 4)], where the first item in each tuple is its index. O(N).zip2!([1 2 3] [4 5 6]) returns the stack of tuples [(1 4) (2 5) (3 6)], where each inner tuple combines the corresponding items from the input tuple of stacks. O(N).zip3!([1 2 3] [4 5 6] [7 8 9]) returns the stack of tuples [(1 4 7) (2 5 8) (3 6 9)], where each inner tuple combines the corresponding items from the input tuple of stacks. O(N).zip4!([1 2] [3 4] [5 6] [7 8]) returns the stack of tuples [(1 3 5 7) (2 4 6 8)], where each inner tuple combines the corresponding items from the input tuple of stacks. O(N).split!(' ' "hey hey, ok") returns ["hey" "hey," "ok"] and split!(1 [1 2 3 1 1 4]) returns [[] [2 3] [] [4]]. O(N).cartesian_product2!([0 1] "ab") returns the stack of tuples [(1 'b') (0 'b') (1 'a') (0 'a')]. O(MN).put_column!([1 2] [[3] [4]]) returns [[1 3] [2 4]]. O(N).transpose![[1 2] [3 4]] returns [[1 3] [2 4]]. O(NM).get!(key table default_value) returns the value corresponding to the key in the table, if it exists, otherwise default_value is returned. O(log N).put!((key value) table) set the value corresponding to the key in the table and returns the table. Note that the table is also mutated so that other references to it are effected as well. O(log N).get_keys!table returns a stack of all keys in the table. O(N).get_values!table returns a stack of all values in the table. O(N).get_items!table returns a stack of tuples, of all pairwise keys and values in the table. O(N).count_elements!container returns a table where the keys are elements from the input container and the values are the number of times they occur in the input container. O(N log N).unique!container returns a stack with the unique elements of the input container. O(N log N).yes, except empty stack [] and empty string "" and number zero 0 and the boolean no which are all converted to no.no, except empty stack [] and empty string "" and number zero 0 and the boolean no which are all converted to yes.yes if all items are yes and otherwise no.yes if any item is yes and otherwise no.yes if all item are no and otherwise yes.yes if they are equal and otherwise no.no if they are equal and otherwise yes.yes if the first is smaller than the second, otherwise no.yes if the first is smaller or equal to the second, otherwise no.yes if the first is larger than the second, otherwise no.0 if the stack is empty.1 if the stack is empty.inf if the stack is empty.-inf if the stack is empty.min_key!(key stack) returns the item in the stack for which the the result of the function application key!item is smallest. Requires the stack to be non-empty.max_key!(key stack) returns the item in the stack for which the result of the function application key!item is largest. Requires the stack to be non-empty..min_predicate!(predicate stack) compares all items in the stack and returns the item that is smallest according to the binary predicate. predicate!(left right) checks if left is smaller than right and returns a boolean. Requires the stack to be non-empty.max_predicate!(predicate stack) compares all items in the stack and returns the item that is largest according to the binary predicate. predicate!(left right) checks if left is smaller than right and returns a boolean. Requires the stack to be non-empty.yes or no.yes or no.yes or no.yes or no.