stdlib 41.2.3 Reference

# Class `std.list`

Tables as lists.

Prototype Chain ---------------

table `-> Object `-> List

## Objects

std.list.List | An Object derived List.

## Functions

std.list.append (l, x) | Append an item to a list.
std.list.compare (l, m) | Compare two lists element-by-element, from left-to-right.
std.list.concat (l, ...) | Concatenate the elements from any number of lists.
std.list.cons (l, x) | Prepend an item to a list.
std.list.rep (l, n) | Repeat a list.
std.list.sub (l[, from=1[, to=#l]]) | Return a sub-range of a list.
std.list.tail (l) | Return a list with its first element removed.

## Metamethods

std.list:__add (l, e) | Append element to list.
std.list:__concat (l, m) | Concatenate lists.
std.list:__le (l, m) | List equality or order operator.
std.list:__lt (l, m) | List order operator.

## Objects

std.list.List
  An Object derived List.

## Functions

Methods

std.list.append (l, x)
  Append an item to a list.

  ### Parameters:

  - l std.list.List a list
  - x item

  ### Returns:

  std.list.List new list with *x* appended

  ### Usage:

      longer = append (short, "last")

std.list.compare (l, m)
  Compare two lists element-by-element, from left-to-right.

  ### Parameters:

  - l std.list.List a list
  - m std.list.List or table another list, or table

  ### Returns:

  -1 if *l* is less than *m*, 0 if they are the same, and 1 if *l* is greater than *m*

  ### Usage:

      if a_list:compare (another_list) == 0 then print "same" end

std.list.concat (l, ...)
  Concatenate the elements from any number of lists.

  ### Parameters:

  - l std.list.List a list
  - ... tuple of lists

  ### Returns:

  std.list.List new list with elements from arguments

  ### Usage:

      --> {1, 2, 3, {4, 5}, 6, 7}
      list.concat ({1, 2, 3}, {{4, 5}, 6, 7})

std.list.cons (l, x)
  Prepend an item to a list.

  ### Parameters:

  - l std.list.List a list
  - x item

  ### Returns:

  std.list.List new list with *x* followed by elements of *l*

  ### Usage:

      --> {"x", 1, 2, 3}
      list.cons ({1, 2, 3}, "x")

std.list.rep (l, n)
  Repeat a list.

  ### Parameters:

  - l std.list.List a list
  - n std.list.List number of times to repeat

  ### Returns:

  std.list.List *n* copies of *l* appended together

  ### Usage:

      --> {1, 2, 3, 1, 2, 3, 1, 2, 3}
      list.rep ({1, 2, 3}, 3)

std.list.sub (l[, from=1[, to=#l]])
  Return a sub-range of a list. (The equivalent of ??? on strings; negative list indices count from the end of the list.)

  ### Parameters:

  - l std.list.List a list
  - from std.list.List start of range (default 1)
  - to std.list.List end of range (default #l)

  ### Returns:

  std.list.List new list containing elements between *from* and *to* inclusive

  ### Usage:

      --> {3, 4, 5}
      list.sub ({1, 2, 3, 4, 5, 6}, 3, 5)

std.list.tail (l)
  Return a list with its first element removed.

  ### Parameters:

  - l std.list.List a list

  ### Returns:

  std.list.List new list with all but the first element of *l*

  ### Usage:

      --> {3, {4, 5}, 6, 7}
      list.tail {{1, 2}, 3, {4, 5}, 6, 7}

## Metamethods

std.list:__add (l, e)
  Append element to list.

  ### Parameters:

  - l std.list.List a list
  - e element to append

  ### See also:

  std.list.append

  ### Usage:

      list = list + "element"

std.list:__concat (l, m)
  Concatenate lists.

  ### Parameters:

  - l std.list.List a list
  - m std.list.List or table another list, or table (hash part is ignored)

  ### See also:

  std.list.concat

  ### Usage:

      new = alist .. {"append", "these", "elements"}

std.list:__le (l, m)
  List equality or order operator.

  ### Parameters:

  - l std.list.List a list
  - m std.list.List another list

  ### See also:

  std.list.compare

  ### Usage:

      min = list1 <= list2 and list1 or list2

std.list:__lt (l, m)
  List order operator.

  ### Parameters:

  - l std.list.List a list
  - m std.list.List another list

  ### See also:

  std.list.compare

  ### Usage:

      max = list1 > list2 and list1 or list2

generated by LDoc 1.5.0 Last updated 2026-07-25 13:31:42