A list is a collection of objects that can change size

Mimics
Inactive cells
Active cells
Specs
Inactive cells (details)
kind = "List"
Active cells (details)
*(sepOrRep)

takes either a text or a number. if given a text, it works like join, while if it gets a number, it will return a new list repeated as many times as the number argument

method(sepOrRep, 
  if(sepOrRep mimics?(Text), 
    self join(sepOrRep), 
    result = list 
    sepOrRep times(result concat!(self)) 
    result))
+(otherList)

returns a new list that contains the receivers elements and the elements of the list sent in as the argument.

-(otherList)

returns a new list that contains all the elements from the receivers list, except for those that are in the argument list

<<(value)

takes one argument and adds it at the end of the list, and then returns the list

<=>(other)

Compares this object against the argument. The comparison is only based on the elements inside the lists, which are in turn compared using <=>.

==(other)

returns true if the left hand side list is equal to the right hand side list.

===(other)

nil

method(other, 
  if(self same?(
      []), 
    Reflector other:mimics?(cell(:other), 
      []), 
    bind(rescue(Condition Error, fn(c, false)), 
      self ==(
        other))))
?&(...)

if this list is not empty, returns the result of evaluating the argument, otherwise returns the list

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    then = call arguments [](
        0) 
    
    unless(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
?|(...)

if this list is empty, returns the result of evaluating the argument, otherwise returns the list

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    then = call arguments [](
        0) 
    
    if(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
[](...)

nil

[]=(...)

nil

append!(value)

takes one argument and adds it at the end of the list, and then returns the list

asList()

returns this list

method(
  self)
assoc(obj)

takes an object, and returns the first list in this list that has that object as its first element. if it can't be found, returns nil.

method(obj, 
  self find(el, 
    el mimics?(List) &&(el length >(0)) &&(el [](0) ==(obj))))
at(index)

takes one argument, the index of the element to be returned. can be negative, and will in that case return indexed from the back of the list. if the index is outside the bounds of the list, will return nil. the argument can also be a range, and will in that case interpret the first index as where to start, and the second the end. the end can be negative and will in that case be from the end. if the first argument is negative, or after the second, an empty list will be returned. if the end point is larger than the list, the size of the list will be used as the end point.

at=(index, value)

takes two arguments, the index of the element to set, and the value to set. the index can be negative and will in that case set indexed from the end of the list. if the index is larger than the current size, the list will be expanded with nils. an exception will be raised if a abs(negative index) is larger than the size.

butLast(n 1)

returns all the entries in the list, except for the 'n' last one, where 'n' is an optional argument that defaults to 1.

method(n 1, 
  end = length -(n) 
  if(end <(0) ||(empty?), 
    DefaultBehavior [], 
    [](0 ...(end))))
choose(quantity nil)

chooses a random element from the list. If a quantity is specified it returns a sequence of random elements each chosen from the complete list (and therefore may contain duplicates)

method(quantity nil, 
  if(quantity, 
    outerList = self 
    left = quantity 
    Sequence with(
      next?: fnx(left >(0)), 
      next: fnx(--(left) 
        outerList random)), 
    random))
clear!()

will remove all the entries from the list, and then returns the list

collect!(...)

nil

compact()

returns a new list that is a mimic of the current list, except that all nils are removed from it

method(
  newList = self mimic 
  newList compact! 
  newList)
compact!()

removes all nils in this list, and then returns the list

concat!(otherList)

adds the elements in the argument list to the current list, and then returns that list

each([indexOrArgOrCode] nil, [argOrCode] nil, [code] nil)

takes either one or two or three arguments. if one argument is given, it should be a message chain that will be sent to each object in the list. the result will be thrown away. if two arguments are given, the first is an unevaluated name that will be set to each of the values in the list in succession, and then the second argument will be evaluated in a scope with that argument in it. if three arguments is given, the first one is an unevaluated name that will be set to the index of each element, and the other two arguments are the name of the argument for the value, and the actual code. the code will evaluate in a lexical context, and if the argument name is available outside the context, it will be shadowed. the method will return the list.

empty?()

returns true if this list is empty, false otherwise

flatten()

returns a new list that is a mimic of the current list, with all elements flattened in it

method(
  newList = self mimic 
  newList flatten! 
  newList)
flatten!()

flattens all lists in this list recursively, then returns it

hash()

returns a hash for the list

ifEmpty(...)

if this list is empty, returns the result of evaluating the argument, otherwise returns the list

macro(
  argCount = call arguments length 
  cond(
    argCount ==(
      1), 
    
    then = call arguments [](
        0) 
    
    if(empty?, 
      call argAt(0), 
      self), 
    error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)) 
  )
include?(object)

returns true if the receiver includes the evaluated argument, otherwise false

index(obj)

takes an object and returns the index of the first occurance of that object in this list, or nil if it doesn't exist

method(obj, 
  self each(index, element, 
    if(element ==(obj), 
      return(index))) 
  nil)
insert!(index, +objects)

takes an index and zero or more objects to insert at that point. the index can be negative to index from the end of the list. if the index is positive and larger than the size of the list, the list will be filled with nils inbetween.

inspect()

Returns a text inspection of the object

join(separator )

returns a text composed of the asText representation of all elements in the list, separated by the separator. the separator defaults to an empty text.

last()

returns the last element of this list, or nil of the list is empty

method(
  if(empty?, nil, [](0 -(1))))
length(...)

nil

map!([argOrCode], [code] nil)

takes one or two arguments, and will then use these arguments as code to transform each element in this list. the transform happens in place. finally the method will return the receiver.

notice()

Returns a brief text inspection of the object

pick(quantity nil)

picks a random element from the list. If a quantity is specified it returns a list of that size picked randomly which is a subset of the original list. If the specified quantity is greater than the length of the list, the returned list will be padded with nils.

method(quantity nil, 
  if(quantity, 
    result = list 
    notPicked = self mimic 
    quantity times(
      result <<(notPicked removeAt!(System randomNumber %((notPicked length))))) 
    result, 
    random))
pick!(quantity nil)

picks and removes a random element from the list. If a quantity is specified it modifies the list by removing that many random elements and returning them in a new list. If the specified quantity is greater than the length of the list, the returned list will be padded with nils.

method(quantity nil, 
  if(quantity, 
    result = list 
    quantity times(
      if(length >(0), 
        result <<(removeAt!(randomIndex)), 
        result <<(nil))) 
    result, 
    removeAt!(randomIndex)))
pop!()

removes the last element from the list and returns it. returns nil if the list is empty.

prepend!(value)

takes one argument and adds it at the beginning of the list, and then returns the list

push!(...)

nil

random()

returns a random element from the list. Returns nil if the list is empty.

method(
  if(length >(0), 
    [](System randomNumber %(length)), 
    nil))
randomIndex()

returns the index of a random element from the list. Returns nil if the list is empty.

method(
  if(length >(0), 
    System randomNumber %(length), 
    nil))
rassoc(obj)

takes an object, and returns the first list in this list that has that object as its second element. if it can't be found, returns nil.

method(obj, 
  self find(el, 
    el mimics?(List) &&(el length >(1)) &&(el [](1) ==(obj))))
remove!(element, +elements)

takes one or more arguments. removes all occurrences of the provided arguments from the list and returns the updated list. if an argument is not contained, the list remains unchanged. sending this method to an empty list has no effect.

removeAt!(indexOrRange)

takes as argument the index of the element to be removed and returns it. can be negative and will in that case index from the back of the list. if the index is outside the bounds of the list, will return nil. the argument can also be a range, and will in that case remove the sublist beginning at the first index and extending to the position in the list specified by the second index (inclusive or exclusive depending on the range). the end of the range can be negative and will in that case index from the back of the list. if the start of the range is negative, or greater than the end, an empty list will be returned. if the end index exceeds the bounds of the list, its size will be used instead.

removeFirst!(element, +elements)

takes one or more arguments. removes the first occurrence of the provided arguments from the list and returns the updated list. if an argument is not contained, the list remains unchanged. arguments that are provided multiple times are treated as distinct elements. sending this message to an empty list has no effect.

removeIf!([argOrCode], [code] nil)

takes one or two arguments, and will then use these arguments as code to decide what elements should be removed from the list. the method will return the receiver.

rest()

returns a list that contains all entries except for the first one, or the empty list if this list is empty.

method(
  if(empty?, 
    DefaultBehavior [], 
    [](1 ..(0 -(1)))))
reverse()

returns a new list that is a mimic of the current list, except that the order of all elements are reversed

method(
  newList = self mimic 
  newList reverse! 
  newList)
reverse!()

reverses the elements in this list, then returns it

rindex(obj)

takes an object and returns the index of the last occurance of that object in this list, or nil if it doesn't exist

method(obj, 
  ((self size -(1)) ..(0)) each(index, 
    if(self [](index) ==(obj), 
      return(index))) 
  nil)
second()

returns the second element of this list, or nil of the list has less than two entries

method(
  [](1))
seq()

returns a new sequence to iterate over this list

shift!()

removes the first element from the list and returns it. returns nil if the list is empty.

shuffle()

return a new list containing the same elements as the original list with their positions distributed randomly.

method(
  pick(length))
shuffle!()

shuffles the list by randomly distributing the position of its elements

method(
  notPicked = self mimic 
  notPicked length times(index, 
    randomIndex = System randomNumber %((notPicked length)) 
    [](index) = notPicked removeAt!(randomIndex)) 
  self)
size()

returns the size of this list

sort()

returns a new sorted version of this list

sort!()

sorts this list in place and then returns it

third()

returns the third element of this list, or nil of the list has less than three entries

method(
  [](2))
unshift!(...)

nil