Scripting Guide > Data Structures > Lists > Evaluate Lists
发布日期: 04/13/2021

Evaluate Lists

When you run a script that contains a list, a copy of the list is returned. The items inside the list are not evaluated.

b = 7;
x = {1, 2, b, Sqrt( 3 )};
Show( x );

x = {1, 2, b, Sqrt(3)};

To evaluate items in a list, use the Eval List() function.

b = 7;
x = {1, 2, b, Sqrt( 3 )};
c = Eval List( x );

{1, 2, 7, 1.73205080756888}

When using a list of variables that reference lists, you will need to use an Eval() function.

Consider the following example, where you have a variable called fullMonth that is a list of 12 items.

::fullMonth = {January, February, March, April, May, June, July, August, September, October, November, December};
::abbrevMonth = {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
::dow = {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
::levels = {Very Low, Low, Medium Low, Medium, Medium High, High, Very High};
::feel = {Strongly Disagree, Disagree, Neutral, Indifferent, Agree, Strongly Agree};
::rating = {Failing, Unacceptable, Very Poor, Poor, Bad, Acceptable, Average, Good, Better, Very Good, Excellent, Best};
::mlist = {::fullMonth, ::abbrevMonth, ::dow, ::levels, ::feel, ::rating};
N Items(::fullMonth); // returns 12 because fullMonth has 12 items.
N Items(::mlist[1]); /* returns this message: "N Items() argument must be a list" because ::mlist[1] is a variable (fullMonth) and fullMonth is a list.*/

When you add the Eval() function:

N Items( Eval( ::mlist[1] ) );

12

/* returns 12 because::mlist[1] holds ::fullMonth, and evaluating it

returns ::fullMonth's list.*/

In a loop, you need the Eval() function in the nested loop to evaluate the variable’s contents. For example:

For( g = 1, g <= N Items( ::mlist ), g++,
    For( i = 1, i <= N Items(::mlist[g]), i++,
        Show( ::mlist[g][i] )
    )
);

// returns the message "N Items() argument must be a list."

To fix the problem, add the Eval() function:

::mlist = {::fullMonth, ::abbrevMonth, ::dow, ::levels, ::feel, ::rating};
For( g = 1, g <= N Items( ::mlist ), g++,
    For( i = 1, i <= N Items( Eval( ::mlist[g] ) ), i++,
        Show( ::mlist[g][i] )
    )
);
需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).