Methods in URScript
Starting from Polyscope 5.15, methods (member functions) are callables on list, matrix and structs (currently). The name of the list followed by a "." will invoke the function.
Methods on List
append(element)
Adds the element to the end of the list. Raises an error if at capacity.
Example: add the value 88 to a list.
l1 = make_list(0, 0, 10) # empty list of integers with capacity of 10
l1.append(88) # add element to the end of the list, length increases, exception thrown if capacity exceeded
capacity()
Returns the maximum capacity of the list (>=length).
Example: merge list 2 to list 1 until list 1 is full. result: [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10]
l1 = make_list(5, -1, 10) l2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] idx = l1.length() while(idx < l1.capacity()): l1.append(l2[idx]) idx = idx + 1 end
clear()
Clear the list by setting length to 0.
list_1.clear() # list_1 will be []
excess_capacity()
Returns the unused capacity (= capacity-length).
Example: add element if the list has free space. result: [9,9,9,9,9,1,2,3,4,5]; popup "no more space"
l1 = make_list(5, 9, 10) l2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] idx = 0 while(idx < l2.length()): if(l1.excess_capacity() > 0): l1.append(l2[idx]) else: popup("no more space") break end idx = idx + 1 end
extend(list of elements)
Adds all elements from the parameter list at the end. Raises an error if at capacity. The list in the input must be of the same type as the list.
Example: add list 2 to list 1. result = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
l1 = make_list(2, 0, 100) l2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] if l1.excess_capacity() >= l2.length(): l1.extend(l2) end
insert(index, element)
Inserts the element at the given index, shifting remaining list. Raises an error if at capacity.
length()
Returns the current length of the list.
Example: update elements of a list in a loop
l1 = [1, 2, 3, 4, 5, 6] idx = 0 while (idx < l1.length()): l1[idx] = 10 + idx idx = idx + 1 end
pop()
Removes the last element from the list.
remove(index)
Removes the element at a given index.
Example: remove even numbers from a collection.
l2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] idx = l2.length() - 1 while(idx > 0): if(l2[idx] % 2 == 0): l2.remove(idx) end idx = idx - 1 end
slice(begin index, end index)
Returns a sub-list of elements [list[param1]... list[param2-1]]. Does not modify the original list.
to_string()
Returns a string representation of the list. has ...] if out of space.
Methods on Struct
length()
Returns the number of elements in the struct.
to_string()
Returns a string representation of the struct. has ...} if out of space.
Methods on Matrix
get_column(index)
Returns the column at the index by value.
get_row(index)
Returns the row at the index by value.
shape()
Returns the number of rows and columns in the matrix.
to_string()
Returns a string representation of the list. has ...] if out of space.