pkg(K;V)

Returns a single, indexed list-value containing key-value pairs.

Function type

Scalar only

Syntax

pkg(K;V)

Input

Argument Type Description
K any The values passed to K are used as keys in the resulting list-value of key-value pairs

A space- or comma-separated list of scalar values

V any The values passed to V are used as the values in the resulting list-value of key-value pairs

A space- or comma-separated list of scalar values

Note: Values in K and values in V are paired in the order which each is passed to their respective parameters.

Return Value

Returns a single list-value that contains a list of key-value pairs (i.e., a dictionary).

If K is N/A, an error is returned.

If V is N/A, an error is returned.

Sample Usage

As an example, the following function call:
package="{pkg('a' 'b' 'c'; 1 2 3)}"
returns a value called package, which itself contains three key values: a, b, and c, and three values corresponding to a key: 1, 2, and 3. The values on either side of the semicolon are paired in order of their appearance. Values can subsequently be accessed via the following syntax:
<willbe name="test" value="{@package.a}"/>
which returns the value 1. The value can be accessed with the alternate syntax:
<willbe name="test" value="{@package['a']}"/>
Note: When using the square bracket syntax the key value must be enclosed in single quotes if it is a string.

Example

<let package="{pkg('a' 'b' 'c';1 2 3)}">
  <willbe name="package_test" value="{@package.a}"/>
</let>

The <willbe> operation in the above <let> clause will be a column with the value 1.

Example: Building keys for value reference

Values in a package may also be accessed using string building to produce key values. The result of any operation used for accessing values must be a valid key for the package being referenced.

<let important_nums="{pkg('pi' 'sqrt_two';3.14159 1.41421)}" 
 op="sqrt_" num="two">
    <willbe name="irrational" value="{@important_nums[splice(@op @num;'')]}"/>
</let>

The code above will produce a column whose value is 1.41421. Notice of the square bracket syntax to improve readability. It is also possible to access the value of the key pi in this manner.

<let important_nums="{pkg('pi' 'sqrt_two';3.14159 1.41421)}" 
 op="sqrt_" num="two">
    <willbe name="irrational" value="{@important_nums[splice(@op @num;'')]}"/>
    <willbe name="irrational2" value="{@important_nums['pi']}"/>
</let>
Note: When using the square bracket syntax the key value must be enclosed in single quotes if it is a string.

Example: Iterating over packages

<foreach> and <for> loops can still be used to iterate over packages. However, since packages do not use integers to locate an index position some massaging is necessary. This example uses the <letseq> clause to create multiple values. The second value is a list of package keys created with the pkg_names(X) function. The following code creates a <foreach> loop that creates a new column for each value in the package by first creating a list-value of the package keys, then loops over that list to access each value in the package.

<letseq stooges="{pkg('stooge_1' 'stooge_2' 'stooge_3';'Larry' 'Curly' 'Moe')}" 
 keys="{pkg_names(@stooges)}">
    <foreach stooge_num="{@keys}" tally_="@i">
        <willbe name="stooge_{@i}" value="'{@stooges.{@stooge_num}}'"/>
    </foreach>
</letseq>