| Qore Programming Language Reference Manual 2.2.0

Loading...
Searching...
No Matches
Public Member Functions | List of all members
<list> Class Reference

Methods in this pseudo-class can be executed on lists. More...

`#include <Pseudo_QC_List.dox.h>`

Inheritance diagram for Qore::<list>:
[legend]

## Public Member Functions
bool | complexType ()
| returns True if the list has a Hash With Declared Value Type, False if not
bool | contains (auto arg)
| Returns True if the list contains arg, False if it does not.
bool | empty ()
| Returns True if the list is empty (size = 0), False if not.
auto | first ()
| Returns the first entry in the list.
AbstractIterator | iterator ()
| Returns a ListIterator object for the list.
string | join (string str)
| Creates a string from the list and a separator string given as an argument.
auto | last ()
| Returns the last entry in the list.
int | lsize ()
| Returns the number of elements in the list.
AbstractIterator | rangeIterator (auto val)
| Returns a RangeIterator object for the list elements.
int | size ()
| Returns the number of elements in the list.
bool | sizep ()
| Returns True since lists can return a non-zero size.
int | typeCode ()
| Returns Qore::NT_LIST.
bool | val ()
| Returns False if the list is empty (size = 0), True if not.
Public Member Functions inherited from <value>
bool | callp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression is a callable value (ie closures or call references)
bool | complexType ()
| returns True if the value has a complex type, False if not
bool | empty ()
| Returns True; this method will be reimplemented in container types where it may return False.
string | fullType (*bool with_namespaces)
| returns the full type name which differs from the simple type name in case of complex types and objects
bool | intp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to an integer.
AbstractIterator | iterator ()
| Returns an iterator object for the value; the default iterator object returned is SingleValueIterator.
int | lsize ()
| Returns 1; the return value of this method should give the list size of the value, which is normally 1 for non-lists (except for NOTHING where the size will be 0) and the number of the elements in the list for lists; this method will be reimplemented in other types where it may return other values.
int | size ()
| Returns zero; this method will be reimplemented in container types where it may return a non-zero value.
bool | sizep ()
| Returns True if the type can return a non-zero size (True for containers including binary objects and strings, False for everything else)
bool | strp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to a string.
bool | toBool ()
| Returns the boolean representation of the value; the default is False.
float | toFloat ()
| Returns the floating-point representation of the value; the default is 0.0.
int | toInt ()
| Returns the integer representation of the value; the default is 0.
number | toNumber ()
| Returns the arbitrary-precision numeric representation of the value; the default is 0.
string | toString (*string encoding)
| Returns the string representation of the value; the default is an empty string.
string | type ()
| Returns the string type for the value.
int | typeCode ()
| Returns the type code for the value.
bool | val ()
| Returns False; this method is reimplemented in other types and will return True if the given expression has a non-empty value.

## Detailed Description

Methods in this pseudo-class can be executed on lists.

## Member Function Documentation

## ◆ complexType()

bool <list>::complexType | ( |  | ) |

returns True if the list has a Hash With Declared Value Type, False if not

Code Flags:
  CONSTANT

Example:
  bool b = n.complexType();

Returns
  True if the list has a Hash With Declared Value Type, False if not

See also
  - <value>::fullType()

Since
  Qore 0.8.13

## ◆ contains()

bool <list>::contains | ( | auto | arg | ) |

Returns True if the list contains arg, False if it does not.

This call uses "soft" comparisons (where types may be converted). The computational complexity is `O(n)` (n = the length of the list).

Code Flags:
  RET_VALUE_ONLY

Parameters

  arg | any value to check its presence in the list

Returns
  True if the list contains arg, False if it does not

Example:
  list<int> l = (1, 2, 3);
  bool b = l.contains(5); # returns False

## ◆ empty()

bool <list>::empty | ( |  | ) |

Returns True if the list is empty (size = 0), False if not.

The opposite of <list>::val()

Returns
  True if the list is empty (size = 0), False if not

Code Flags:
  CONSTANT

Example:
  bool b = l.empty();

## ◆ first()

auto <list>::first | ( |  | ) |

Returns the first entry in the list.

Returns
  the first entry in the list

Code Flags:
  CONSTANT

Example:
  auto e = l.first();

See also
  <list>::last()

Since
  Qore 0.8.5

## ◆ iterator()

AbstractIterator <list>::iterator | ( |  | ) |

Returns a ListIterator object for the list.

Returns
  a ListIterator object for the list

Code Flags:
  CONSTANT

Example:
  map printf("+ %y\n", $1), l.iterator();

Since
  Qore 0.8.6

## ◆ join()

string <list>::join | ( | string | str | ) |

Creates a string from the list and a separator string given as an argument.

Each element in the list will be converted to a string if necessary to be concatenated to the return value string; additionally if any string argument has a different character encoding than str, then it will be converted to str's character encoding before concatentation to the return value string

Code Flags:
  RET_VALUE_ONLY

Parameters

  str | the separator string

Returns
  a string created from a list and a separator string, each element in the list will be present in the return value separated by the separator string; the string returned with have the same character encoding as str

Example:
  string str = ("a", "b", "c").join(":"); # returns "a:b:c"

Exceptions

  ENCODING-CONVERSION-ERROR | this exception could be thrown if the string arguments have different character encodings and an error occurs during encoding conversion

Note
  equivalent to join(string, list)

Since
  Qore 0.8.5

## ◆ last()

auto <list>::last | ( |  | ) |

Returns the last entry in the list.

Returns
  the last entry in the list

Code Flags:
  CONSTANT

Example:
  auto e = l.last();

See also
  <list>::first()

Since
  Qore 0.8.5

## ◆ lsize()

int <list>::lsize | ( |  | ) |

Returns the number of elements in the list.

For this type, this method is equivalent to size()

Returns
  the number of elements in the list

Code Flags:
  CONSTANT

Example:
  printf("iterating %d element%s\n", val.lsize(), val.lsize() == 1 ? "" : "s");
  foreach auto element in (val) {
  do_something(element);
  }

## ◆ rangeIterator()

AbstractIterator <list>::rangeIterator | ( | auto | val | ) |

Returns a RangeIterator object for the list elements.

Code Flags:
  CONSTANT

Example:
  map printf("+ %y\n", $1), l.ranegIterator();

Parameters

  val | an optional value to be returned instead of the default integer value

Returns
  a RangeIterator object for the list elements

Since
  - Qore 0.8.8
  - Qore 0.8.11.1 this pseudo-method takes the optional val argument

## ◆ size()

int <list>::size | ( |  | ) |

Returns the number of elements in the list.

Returns
  the number of elements in the list

Code Flags:
  CONSTANT

Example:
  int len = l.size();

See also
  <list>::sizep()

## ◆ sizep()

bool <list>::sizep | ( |  | ) |

Returns True since lists can return a non-zero size.

Code Flags:
  CONSTANT

Returns
  True since lists can return a non-zero size

See also
  <list>::size()

Since
  Qore 0.8.9

## ◆ typeCode()

int <list>::typeCode | ( |  | ) |

Returns Qore::NT_LIST.

Returns
  Qore::NT_LIST

Code Flags:
  CONSTANT

Example:
  switch (l.typeCode()) {
  case NT_LIST:
  printf("%y: is a list\n", l);
  break;
  }

## ◆ val()

bool <list>::val | ( |  | ) |

Returns False if the list is empty (size = 0), True if not.

The opposite of <list>::empty()

Returns
  False if the list is empty (size = 0), True if not

Code Flags:
  CONSTANT

Example:
  bool b = l.val();

See also
  - %perl-bool-eval
  - %strict-bool-eval