NAME

pack - creates a packed copy of the given heterogenous array

SYNOPSIS

arr.pack()

DESCRIPTION

The pack() builtin method creates a packed copy of the given heterogenous array.

The following table issustrates how values of different types are combined in packed arrays. The cells highlighted in green indicate the types which force a promotion to the packed type on the left.

If the table entry is blank, then pack() will return an Array or List copy of the original arr.

Bool Char Byte Ubyte Short Ushort Half WideChar Int Uint Float Long Ulong Double Other
PackBool Y
String2 Y
PackChar3 Y
PackByte Y Y
PackUbyte Y Y1 Y
PackShort Y Y Y Y
PackUshort Y Y1 Y Y1 Y
PackHalf Y Y Y Y Y Y
WideString2 Y Y1 Y Y1 Y Y
PackWideChar3 Y Y1 Y Y1 Y Y
PackInt Y Y Y Y Y Y Y
PackUint Y Y1 Y Y1 Y Y Y1 Y
PackFloat Y Y Y Y Y Y Y Y Y Y
PackLong Y Y Y Y Y Y Y Y Y
PackUlong Y Y1 Y Y1 Y Y Y1 Y Y1 Y
PackDouble Y Y Y Y Y Y Y Y Y Y Y Y Y
List2 Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Array3 Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y

1 Non-negative values only
2 Only one dimension
3 More than one dimension

RETURN VALUE

A packed copy of the original array, or a heterogenous List or Array copy if the original array is not packable.

ERRORS

TypeCheck if arr is not an array or Object

EXAMPLE

    a = {1, 2.0, 3.5d}
    typeof(a.pack())
PackDouble

    a = {true, nil, "foo"}
    b = a.pack()
    typeof(b)
List

    b[1] = 3
    b
true 3 foo

    a
true nil foo

SEE ALSO

unpack