🎨
Xylo Docs
  • Introduction
  • Getting Started
    • Quickstart
  • Guides
    • Random Rotations
  • Syntax
    • Primitives
    • Functions
  • Control Flow
  • Builtin Functions
    • System
    • Math
    • Comparison
    • List
    • Randomness
    • Shape
    • Color
Powered by GitBook
On this page
  • List Operators
  • Query Functions
  • Modification Functions
  • Transformation Functions
  • Reduction Functions
Export as PDF
  1. Builtin Functions

List

List Operators

range from to

Generates a list of all numbers between from (inclusive) and to (exclusive). List elements can be integer or float types.

Equivalent to the (..) binary operator.

Example:

one_two_three = range 1 4
one_two_three = (..) 1 4
one_two_three = 1 .. 4

rangei from to

Returns a list of all numbers between from (inclusive) and to (inclusive). List elements can be integer or float types.

Equivalent to the (..=) binary operator.

Example:

one_two_three = rangei 1 3
one_two_three = (..=) 1 3
one_two_three = 1 ..= 3

concat x y

Returns a list of length 2 containing x as the first element and y as the second element. x and y must be of the same type.

Equivalent to the (++) binary operator.

Example:

one_two = concat 1 2
one_two = (++) 1 2
one_two = 1 ++ 2

prepend value list

Return a new list with value added to the start of list. value must be the same type as the elements of list.

Equivalent to the (+>) binary operator.

Example:

one_two_three = prepend 1 [2, 3]
one_two_three = (+>) 1 [2, 3]
one_two_three = 1 +> [2, 3]

append list value

Return a new list with value added to the end of list. value must be the same type as the elements of list.

Equivalent to the (<+) binary operator.

Example:

one_two_three = append [1, 2] 3
one_two_three = (<+) [1, 2] 3
one_two_three = [1, 2] <+ 3

Query Functions

nth index list

Returns the element at index of list. index must be of the integer type.

Example:

two = nth 1 [1, 2, 3]

length list

Returns the number of elements in list.

Example:

three = length [1, 2, 3]

is_empty list

Returns true if length of list is zero, false otherwise.

Example:

true_ = is_empty []

contains value list

Returns true if value is equal to an element in list, false otherwise.

Example:

true_ = contains 3 [1, 2, 3]

index_of value list

Returns the index of first element in list that is equal to value, -1 if not found.

Example:

one = index_of 2 [1, 2, 3, 2]

Modification Functions

set index value list

Returns a new list where element of list at index is replaced with value. index must be of the integer type and value must be the same type as elements of list.

Example:

one_two_three = set 1 2 [1, 3, 3]

head list

Returns the first element of list.

Example:

one = head [1, 2, 3]

tail list

Returns a new list containing all elements of list except the first one.

Example:

two_three = tail [1, 2, 3]

init list

Returns a new list containing all elements of list except the last one.

Example:

one_two = init [1, 2, 3]

last list

Returns the last element of list.

Example:

three = last [1, 2, 3]

take count list

Returns a new list containing the first count elements of list, or the last elements if count is negative. count must be of the integer type.

Example:

one_two_three = take 3 [1, 2, 3, 4, 5]
three_four_five = take -3 [1, 2, 3, 4, 5]

drop count list

Returns a new list excluding the first count elements of list, or the last elements if count is negative. count must be of the integer type.

Example:

three_four_five = drop 2 [1, 2, 3, 4, 5]
one_two_three = drop -2 [1, 2, 3, 4, 5]

slice start end list

Returns a new list containing elements from list between the start and end indices. start and end must be of the integer type.

Example:

two_three = slice 1 3 [1, 2, 3, 4, 5]

split index list

Divides list into two parts at index, returning a two-dimensional list containing the two resulting sublists. index must be of the integer type.

Example:

true_ = [[1, 2], [3, 4]] == split 2 [1, 2, 3, 4]

Transformation Functions

reverse list

Returns a new list with the elements of list in reverse order.

Example:

three_two_one = reverse [1, 2, 3]

unique list

Returns a new list containing only the distinct elements of list, removing duplicates.

Example:

one_two_three = unique [1, 2, 1, 2, 3, 3, 3]

sort list

Returns a new list with the elements of list sorted in ascending order.

Example:

one_two_three = sort [1, 3, 2]

flatten list

Returns a new list by concatenating all nested lists within list into a single, one-dimensional list.

Example:

one_two_three = flatten [[1, 2], [3]]

intersperse value list

Returns a new list with a specified value inserted between each element of list. value must be of the same type of the elements of list.

Example:

one_four_two_four_three = intersperse 4 [1, 2, 3]

Reduction Functions

min_of list

Returns the smallest element of list. Elements of list must be of the integer or float types.

Example:

one = min_of [2, 1, 3]

max_of list

Returns the largest element of list. Elements of list must be of the integer or float types.

Example:

three = max_of [1, 3, 2]

sum list

Returns the total sum of all elements in list. Elements of list must be of the integer, float, or complex types.

Example:

ten = sum [1, 2, 3, 4]

product list

Returns the total product of all elements in list. Elements of list must be of the integer, float, or complex types.

Example:

twenty_four = product [1, 2, 3, 4]
PreviousComparisonNextRandomness

Last updated 5 days ago