For the latest version of JMP Help, visit JMP.com/help.


Publication date: 06/21/2023

Subscripts in Lists

In JSL, subscripts extract specified items from a list. Use a list as a subscript to return multiple items from a list.

Note: JSL starts counting from 1, so the first element in a list is [1], not [0] as in some other languages.

Examples

List a contains four items.

a = {"bob", 4, [1, 2, 3], {x, y, z}};
Show( a[1] );

a[1] = "bob";

Show( a[{1, 3}] );

a[{1, 3}] = {"bob", [1, 2, 3]};

a[2] = 5; // assign 5 to the second list item

You can also use subscripts to select or change items in a list:

Show( a );

a = {"bob", 5, [1, 2, 3], {x, y, z}};

c = {1, 2, 3};
c[{1, 2}] = {4, 4};

// c[{1, 2}] = 4 produces the same result

Show( c );

c = {4, 4, 3};

When you have assignments or functions in a list, you can use a quoted name for the subscript to extract the value.

x={sqrt( 4 ), log( 3 )};
xx= {a = 1, b = 3, c = 5};
x["sqrt"];

4

xx["b"];

3

The name must be in quotation marks, or else JMP tries to evaluate it and use its value. The following example shows the values of the second item in the list, rather than the value of a in the list.

a = 2;
Show( xx[a] );

xx[a] = b = 3;

Notes:

Multiple left-side subscripts (for example, a[i][j] = value where a contains a list of things that are subscriptable) are allowed in the following circumstances:

Each level except the outermost level must be a list. So, in the example above, a must be a list but a[i] can be anything subscriptable.

Each subscript except the last must be a number. So, in the example above, i must be a number, but j could be a matrix or list of indices.

Subscripting can be done to any level of nesting, such as the following:

a[i][j][k][l][m][n] = 99;

Note: To get a value in the matrix of an expression column, use double subscripts, as in :Discrim Data Matrix[row()][i].

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).