NAME

length - returns the length of a value

SYNOPSIS

val.length()
oadl::length(val)

DESCRIPTION

The length() method returns the length of a given val. The length is defined in varous ways depending on the type of val:

Type length()
Array[*] The size of the first axis of the array
Dict The number of assigned elements of the Dict
Object The number of public elements of the Object
Proc The length of the bytecode of the Proc (if defined with the "[]" attribute)

The length() is an intuitive quey for single-dimensional arrays (such as Strings and WideStrings); however, it can also be useful for multi-dimensional arrays.

Note that classes may overload the length() method. It is generally therefore safer to use the oadl::length() intrinsic call for objects.

RETURN VALUE

An Int which is the length of the given val

ERRORS

TypeCheck if val is not an array, Dict, Object, or Proc.
AccessCheck if val is a Proc not defined with the "[]" attribute
ArgCheck if any arguments are passed

EXAMPLES

    "Hello".length()
5

    a = [2,3].iterate()
    a.length()
2

    for (var i = 0; i < a.length(); i++) {
        "Row ", i, ": ", a[i], '\n';
    }
Row 0: 0 1 2
Row 1: 3 4 5

    nil.length()
Illegal type

    d = new Dict(4)
    d.length()
0

    d["one"] = 1
    d.length()
1

    proc "[]" foo() { "Hello, foo!\n"; }
    proc bar() {"Hello, bar!\n"; }
    foo.length()
27

    bar.length()
Access failure

    class ack {
        public var a, b;
        var c;
    }
    ack.length()
3

    forall (ack.(pub)) { "", pub, '\n'; }
parent
a
b

SEE ALSO

shape
width
rank
stride
sizeof