Qore Programming Language Reference Manual  0.8.11.1
List Functions

Functions

bool Qore::inlist ()
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
bool Qore::inlist (any arg, nothing x)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
bool Qore::inlist (any arg, softlist l)
 Returns True if the first argument is a member of the second argument list using soft comparisons (with implicit type conversions), False if not. More...
 
bool Qore::inlist_hard ()
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
bool Qore::inlist_hard (any arg, nothing x)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
bool Qore::inlist_hard (any arg, softlist l)
 Returns True if the first argument is a member of the second argument list using hard comparisons (without any implicit type conversions), False if not. More...
 
any Qore::max (list l)
 Returns the maximum value in a list. More...
 
any Qore::max (list l, string func)
 Returns the maximum value in a list; accepts the name of a function to use to compare complex data types or to give a special sort order. More...
 
any Qore::max (list l, code f)
 Returns the maximum value in a list; accepts a call reference or a closure to use to compare complex data types or to give a special sort order. More...
 
any Qore::max (...)
 Returns the maximum value of the arguments passed to the function. More...
 
any Qore::min (list l)
 Returns the minumum value in a list. More...
 
any Qore::min (list l, string func)
 Returns the minumum value in a list; accepts the name of a function to use to compare complex data types or to give a special sort order. More...
 
any Qore::min (list l, code f)
 Returns the minumum value in a list; accepts a call reference or a closure to use to compare complex data types or to give a special sort order. More...
 
any Qore::min (...)
 Returns the minumum value of the arguments passed to the function. More...
 
list Qore::range (int start, int stop, int step=1)
 Returns a list containing an arithmetic progression of integers. More...
 
list Qore::range (int stop)
 Returns a list containing an arithmetic progression of integers with start = 0 and step = 1. More...
 
nothing Qore::reverse ()
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
list Qore::reverse (list l)
 Reverses a list and returns the new list. More...
 
any Qore::sort (any arg)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
list Qore::sort (list l)
 Performs an unstable sort in ascending order and returns the new list. More...
 
list Qore::sort (list l, string func)
 Performs an unstable sort in ascending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order. More...
 
list Qore::sort (list l, code f)
 Performs an unstable sort in ascending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order. More...
 
any Qore::sortDescending (any arg)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
list Qore::sortDescending (list l)
 Performs an unstable sort in descending order and returns the new list. More...
 
list Qore::sortDescending (list l, string func)
 Performs an unstable sort in descending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order. More...
 
list Qore::sortDescending (list l, code f)
 Performs an unstable sort in descending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order. More...
 
any Qore::sortDescendingStable (any arg)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
list Qore::sortDescendingStable (list l)
 Performs a stable sort in descending order and returns the new list. More...
 
list Qore::sortDescendingStable (list l, string func)
 Performs a stable sort in descending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order. More...
 
list Qore::sortDescendingStable (list l, code f)
 Performs a stable sort in descending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order. More...
 
any Qore::sortStable (any arg)
 This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments. More...
 
list Qore::sortStable (list l)
 Performs a stable sort in ascending order and returns the new list. More...
 
list Qore::sortStable (list l, string func)
 Performs a stable sort in ascending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order. More...
 
list Qore::sortStable (list l, code f)
 Performs a stable sort in ascending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order. More...
 

Detailed Description

List functions

Function Documentation

bool Qore::inlist ( )

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
bool Qore::inlist ( any  arg,
nothing  x 
)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
bool Qore::inlist ( any  arg,
softlist  l 
)

Returns True if the first argument is a member of the second argument list using soft comparisons (with implicit type conversions), False if not.

Code Flags:
RET_VALUE_ONLY
Example:
if (inlist($str, $strlist))
printf("%y is in %y\n", $str, $strlist);
Parameters
argthe argument to look for in the list
lthe list to search for the first argument arg
Returns
True if the first argument is a member of the second argument list using soft comparisons (with implicit type conversions), False if not
See also
inlist_hard(any, softlist)
bool Qore::inlist_hard ( )

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
bool Qore::inlist_hard ( any  arg,
nothing  x 
)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
bool Qore::inlist_hard ( any  arg,
softlist  l 
)

Returns True if the first argument is a member of the second argument list using hard comparisons (without any implicit type conversions), False if not.

Code Flags:
RET_VALUE_ONLY
Example:
if (inlist_hard($str, $strlist))
printf("%y is in %y\n", $str, $strlist);
Parameters
argthe argument to look for in the list
lthe list to search for the first argument arg
Returns
True if the first argument is a member of the second argument list using hard comparisons (without any implicit type conversions), False if not
See also
inlist(any, softlist)
any Qore::max ( list  l)

Returns the maximum value in a list.

This variant will only work on basic data types

Code Flags:
CONSTANT
Example:
my any $v = max($l);
Parameters
lthe list to process
Returns
the maximum value in a list
See also
min(list)
any Qore::max ( list  l,
string  func 
)

Returns the maximum value in a list; accepts the name of a function to use to compare complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my any $v = max($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the maximum value in a list
See also
min(list, string)
any Qore::max ( list  l,
code  f 
)

Returns the maximum value in a list; accepts a call reference or a closure to use to compare complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my any $v = max($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the call reference or a closure must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the maximum value in a list
See also
min(list, code)
any Qore::max (   ...)

Returns the maximum value of the arguments passed to the function.

This variant will only work on basic data types

Code Flags:
CONSTANT
Example:
my any $v = max($v1, $v2, $v3);
Parameters
...the list of values to process given directly to the function
Returns
the maximum value in a list
See also
min(...)
any Qore::min ( list  l)

Returns the minumum value in a list.

This variant will only work on basic data types

Code Flags:
CONSTANT
Example:
my any $v = min($l);
Parameters
lthe list to process
Returns
the minumum value in a list
See also
max(list)
any Qore::min ( list  l,
string  func 
)

Returns the minumum value in a list; accepts the name of a function to use to compare complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my any $v = min($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the minumum value in a list
See also
max(list, string)
any Qore::min ( list  l,
code  f 
)

Returns the minumum value in a list; accepts a call reference or a closure to use to compare complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my any $v = min($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the call reference or a closure must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the minumum value in a list
See also
max(list, code)
any Qore::min (   ...)

Returns the minumum value of the arguments passed to the function.

This variant will only work on basic data types

Code Flags:
CONSTANT
Example:
my any $v = min($v1, $v2, $v3);
Parameters
...the list of values to process given directly to the function
Returns
the minumum value in a list
See also
max(...)
list Qore::range ( int  start,
int  stop,
int  step = 1 
)

Returns a list containing an arithmetic progression of integers.

Code Flags:
RET_VALUE_ONLY
Example:
range(2, 5); # (2, 3, 4, 5)
range(2, -2); # (2, 1, 0, -1, -2)
range(1, 10, 5); # (1, 6)
range(0, 10, 5); # (0, 5, 10)
range(-10, 10, 5); # (-10, -5, 0, 5, 10)
range(10, -10, 5); # (10, 5, 0, -5, -10)
Parameters
startthe initial value
stopthe final value
stepthe step; the default is 1; must be greater than 0; the function throws a RANGE-ERROR exception when this argument is < 1
Returns
Returns a list containing an arithmetic progression of integers.
Exceptions
RANGE-ERRORthis exception is thrown if step < 1
See also
xrange
Note
the main difference between range() and xrange() is that range returns real list and xrange returns a RangeIterator
Since
Qore 0.8.6
list Qore::range ( int  stop)

Returns a list containing an arithmetic progression of integers with start = 0 and step = 1.

This is an overloaded version of range(int, int, int) meaning range(0, stop, 1)

Code Flags:
CONSTANT
Example:
range(1); # (0, 1)
range(-3); # (0, -1, -2, -3)
Parameters
stopthe final value
Returns
Returns a list containing an arithmetic progression of integers with start = 0 and step = 1.
See also
xrange
Note
the main difference between range() and xrange() is that range returns real list and xrange returns a RangeIterator
Since
Qore 0.8.6
nothing Qore::reverse ( )

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
list Qore::reverse ( list  l)

Reverses a list and returns the new list.

Code Flags:
CONSTANT
Example:
my list $nl = reverse($l);
Parameters
lthe list to reverse
Returns
the given list with all elements in reverse order
See also
reverse(string)
any Qore::sort ( any  arg)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
list Qore::sort ( list  l)

Performs an unstable sort in ascending order and returns the new list.

This variant will only sort basic data types

Code Flags:
CONSTANT
Example:
my list $nl = sort($l);
Parameters
lthe list to sort
Returns
the sorted list
See also
list Qore::sort ( list  l,
string  func 
)

Performs an unstable sort in ascending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my list $nl = sort($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
list Qore::sort ( list  l,
code  f 
)

Performs an unstable sort in ascending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my list $nl = sort($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the code must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
any Qore::sortDescending ( any  arg)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
list Qore::sortDescending ( list  l)

Performs an unstable sort in descending order and returns the new list.

This variant will only sort basic data types

Code Flags:
CONSTANT
Example:
my list $nl = sortDescending($l);
Parameters
lthe list to sort
Returns
the sorted list
See also
list Qore::sortDescending ( list  l,
string  func 
)

Performs an unstable sort in descending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order.

Code Flags:
CONSTANT
Example:
my list $nl = sortDescending($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
list Qore::sortDescending ( list  l,
code  f 
)

Performs an unstable sort in descending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my list $nl = sortDescending($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the code must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
any Qore::sortDescendingStable ( any  arg)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
list Qore::sortDescendingStable ( list  l)

Performs a stable sort in descending order and returns the new list.

This variant will only sort basic data types

Code Flags:
CONSTANT
Example:
my list $nl = sortDescendingStable($l);
Parameters
lthe list to sort
Returns
the sorted list
See also
list Qore::sortDescendingStable ( list  l,
string  func 
)

Performs a stable sort in descending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my list $nl = sortDescending($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
list Qore::sortDescendingStable ( list  l,
code  f 
)

Performs a stable sort in descending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my list $nl = sortDescending($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the code must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
any Qore::sortStable ( any  arg)

This function variant does nothing at all; it is only included for backwards-compatibility with qore prior to version 0.8.0 for functions that would ignore type errors in arguments.

Code Flags:
NOOP
list Qore::sortStable ( list  l)

Performs a stable sort in ascending order and returns the new list.

This variant will only sort basic data types

Code Flags:
CONSTANT
Example:
my list $nl = sortStable($l);
Parameters
lthe list to sort
Returns
the sorted list
See also
list Qore::sortStable ( list  l,
string  func 
)

Performs a stable sort in ascending order and returns the new list; accepts the name of a function to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my list $nl = sortStable($l, "my_sort_function");
Parameters
lthe list to sort
functhe name of a function accessible in the current scope that accepts 2 arguments of the data type in the list; the function must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also
list Qore::sortStable ( list  l,
code  f 
)

Performs a stable sort in ascending order and returns the new list; accepts a call reference or a closure to use to sort complex data types or to give a special sort order.

Code Flags:
RET_VALUE_ONLY
Example:
my code $sort_func = int sub (hash $l, hash $r) { return $l.id <=> $r.id; };
my list $nl = sortStable($l, $sort_func);
Parameters
lthe list to sort
fa call reference or a closure that accepts 2 arguments of the data type in the list; the code must return -1, 0, or 1 if the first is less than the second, if the first and second are equal, or if the first is greater than the second, respectively
Returns
the sorted list
See also