| kind | = | "List" |
A list is a collection of objects that can change size
- *(sepOrRep)
- +(otherList)
- -(otherList)
- <<(value)
- <=>(other)
- ==(other)
- ===(other)
- ?&(...)
- ?|(...)
- [](...)
- []=(...)
- append!(value)
- asList()
- assoc(obj)
- at(index)
- at=(index, value)
- butLast(n 1)
- choose(quantity nil)
- clear!()
- collect!(...)
- compact()
- compact!()
- concat!(otherList)
- each([indexOrArgOrCode] nil, [argOrCode] nil, [code] nil)
- empty?()
- flatten()
- flatten!()
- hash()
- ifEmpty(...)
- include?(object)
- index(obj)
- insert!(index, +objects)
- inspect()
- join(separator )
- last()
- length(...)
- map!([argOrCode], [code] nil)
- notice()
- pick(quantity nil)
- pick!(quantity nil)
- pop!()
- prepend!(value)
- push!(...)
- random()
- randomIndex()
- rassoc(obj)
- remove!(element, +elements)
- removeAt!(indexOrRange)
- removeFirst!(element, +elements)
- removeIf!([argOrCode], [code] nil)
- rest()
- reverse()
- reverse!()
- rindex(obj)
- second()
- seq()
- shift!()
- shuffle()
- shuffle!()
- size()
- sort()
- sort!()
- third()
- unshift!(...)
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
[ show source ]
method(sepOrRep,
if(sepOrRep mimics?(Text),
self join(sepOrRep),
result = list
sepOrRep times(result concat!(self))
result))
returns a new list that contains the receivers elements and the elements of the list sent in as the argument.
returns a new list that contains all the elements from the receivers list, except for those that are in the argument list
Compares this object against the argument. The comparison is only based on the elements inside the lists, which are in turn compared using <=>.
nil
[ show source ]
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
[ show source ]
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
[ show source ]
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))
)
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.
[ show source ]
method(obj,
self find(el,
el mimics?(List) &&(el length >(0)) &&(el [](0) ==(obj))))
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.
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.
returns all the entries in the list, except for the 'n' last one, where 'n' is an optional argument that defaults to 1.
[ show source ]
method(n 1,
end = length -(n)
if(end <(0) ||(empty?),
DefaultBehavior [],
[](0 ...(end))))
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)
[ show source ]
method(quantity nil,
if(quantity,
outerList = self
left = quantity
Sequence with(
next?: fnx(left >(0)),
next: fnx(--(left)
outerList random)),
random))
returns a new list that is a mimic of the current list, except that all nils are removed from it
[ show source ]
method( newList = self mimic newList compact! newList)
adds the elements in the argument list to the current list, and then returns that list
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.
returns a new list that is a mimic of the current list, with all elements flattened in it
[ show source ]
method( newList = self mimic newList flatten! newList)
if this list is empty, returns the result of evaluating the argument, otherwise returns the list
[ show source ]
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))
)
takes an object and returns the index of the first occurance of that object in this list, or nil if it doesn't exist
[ show source ]
method(obj,
self each(index, element,
if(element ==(obj),
return(index)))
nil)
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.
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.
returns the last element of this list, or nil of the list is empty
[ show source ]
method( if(empty?, nil, [](0 -(1))))
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.
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.
[ show source ]
method(quantity nil,
if(quantity,
result = list
notPicked = self mimic
quantity times(
result <<(notPicked removeAt!(System randomNumber %((notPicked length)))))
result,
random))
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.
[ show source ]
method(quantity nil,
if(quantity,
result = list
quantity times(
if(length >(0),
result <<(removeAt!(randomIndex)),
result <<(nil)))
result,
removeAt!(randomIndex)))
takes one argument and adds it at the beginning of the list, and then returns the list
returns a random element from the list. Returns nil if the list is empty.
[ show source ]
method(
if(length >(0),
[](System randomNumber %(length)),
nil))
returns the index of a random element from the list. Returns nil if the list is empty.
[ show source ]
method(
if(length >(0),
System randomNumber %(length),
nil))
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.
[ show source ]
method(obj,
self find(el,
el mimics?(List) &&(el length >(1)) &&(el [](1) ==(obj))))
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.
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.
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.
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.
returns a list that contains all entries except for the first one, or the empty list if this list is empty.
[ show source ]
method(
if(empty?,
DefaultBehavior [],
[](1 ..(0 -(1)))))
returns a new list that is a mimic of the current list, except that the order of all elements are reversed
[ show source ]
method( newList = self mimic newList reverse! newList)
takes an object and returns the index of the last occurance of that object in this list, or nil if it doesn't exist
[ show source ]
method(obj,
((self size -(1)) ..(0)) each(index,
if(self [](index) ==(obj),
return(index)))
nil)
returns the second element of this list, or nil of the list has less than two entries
[ show source ]
method( [](1))
return a new list containing the same elements as the original list with their positions distributed randomly.
[ show source ]
method( pick(length))
shuffles the list by randomly distributing the position of its elements
[ show source ]
method(
notPicked = self mimic
notPicked length times(index,
randomIndex = System randomNumber %((notPicked length))
[](index) = notPicked removeAt!(randomIndex))
self)
returns the third element of this list, or nil of the list has less than three entries
[ show source ]
method( [](2))