cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
ThomasDickel
Level III

Map Value function: Inconsistent results for subsequent calls

Hello,

I am new to JMP 16 and JSL but I am an experienced programmer.

 

For some reasons I want to use the "Map Value" function but this gives me wrong results.

What i want to achieve is to remove unwanted items given as a list from a list containing numbers and strings

 

The following function constructs a list for "Map Value" named na_values in the form {option1, 0, option2, 0, ...} from the na_list e.g. {option1, option2 ,...}

and filters it using "Filter Each" and the Map Value" function.

wrap = function({filtered list,na_list}, {Default Local},			
		na_values={};For Each( {value}, na_list, na_values=Insert(na_values,value);na_values=Insert(na_values,1););
		return(Filter Each({value}, filtered list, Map Value(value, na_values, Unmatched(0))==0;));		
);

But it gives a wrong result if I call the function again with other parameters:

 

Show(wrap({"b",1, 2, 3},{"b"}));  // <--  returns {1,2,3} => OK
Show(wrap({"d",1, 2, 3},{"d"}));  // <--  returns {"d",1,2,3} => NOT OK, should be as above {1,2,3]

What is wrong here? A bug in JMP? I am using version 16.0.0 (512257).

 

Best regards,

Thomas

1 ACCEPTED SOLUTION

Accepted Solutions
ThomasDickel
Level III

Re: Map Value function: Wrong results for different characters

The JMP support has answered me, it may be a defect which I have found.

 

Their support gave me the following solution to my original problem to remove unneeded items from a list using the Associative Array function:

 

filtered list = {"b", 1, 2, 3};
na_list = {"b"};
result = Associative Array(filtered list) << Remove(Associative Array(na_list)) << Get Keys; // {1, 2, 3}

View solution in original post

6 REPLIES 6
ErraticAttack
Level VI

Re: Map Value function: Wrong results for different characters

Sometimes JMP / JSL can be weird in how it handles expressions -- for instance, often times in a send function the arguments are sent unevaluated.  Although there is no send function here it would seem that something within the Filter Each() or Map Value() handles arguments in a weird way and handles the lookup oddly.

 

Basically, I cannot say that it is a bug but it does seem weird.  If I were you I'd contact JMP Support and show them that the first call (whether it's the {"b",1,2,3"} or the {"d",1,2,3}) works, while the second does not work.  Possible that it's a bug.

 

Here is a work-around:

wrap = Function( {filtered list, na_list},
	{Default Local},
	na_values = {};
	For Each( {value}, na_list,
		Insert Into( na_values, value );
		Insert Into( na_values, 1 );
	);
	Eval( Eval Expr( Filter Each( {value}, filtered list, Map Value( value, Expr( na_values ), Unmatched( 0 ) ) == 0 ) ) );
);

 

Jordan
David_Burnham
Super User (Alumni)

Re: Map Value function: Wrong results for different characters

I'm not sure how you got your function to work without first initialising na_value as an empty list.  This works:

 

names default to here(1);

filtered list = {"d",1, 2, 3};
na_list = {"d"};

na_values = {};			// <--- missing
For Each( {value}, na_list, 
	na_values=Insert(na_values,value);
	na_values=Insert(na_values,1);
);

f = Filter Each({value}, filtered list, 
	Map Value(value, na_values, Unmatched(0))==0;
);

show(f);
-Dave
ThomasDickel
Level III

Re: Map Value function: Wrong results for different characters

Hello, you are right, I removed the initialization of na_values from my test function.

But the problem exists if I add the initialization of na_values to the function:

 

wrap = function({filtered list,na_list}, {Default Local},			
		na_values={};For Each( {value}, na_list, na_values=Insert(na_values,value);na_values=Insert(na_values,1););
		return(Filter Each({value}, filtered list, Map Value(value, na_values, Unmatched(0))==0;));		
);

Show(wrap({"b",1, 2, 3},{"b"})); // = {1, 2, 3}=> OK 
Show(wrap({"d",1, 2, 3},{"d"})); // = {"d", 1, 2, 3} => Not OK ! => expected {1, 2, 3}

Please try yourself the above code.

David_Burnham
Super User (Alumni)

Re: Map Value function: Wrong results for different characters

In your example 

 

Show(wrap({"b",1, 2, 3},{"b"})); 
Show(wrap({"d",1, 2, 3},{"d"}));

doesn't give the correct results for the 2nd call.

 

But this works:

 

Show(wrap({"d",1, 2, 3},{"d"}));

Which would suggest that you shouldn't need to throw evals all over the place. 

 

The issue is that the 1st call to the function works, and subsequent calls fail; which is very strange.

-Dave
ThomasDickel
Level III

Re: Map Value function: Wrong results for different characters

Thanks for your reply. As you have said the first call works, the subsequent calls fail.

 

I have called our JMP support about this problem which has given this issue to its technical support team. If I get any news to that I will post it here.

ThomasDickel
Level III

Re: Map Value function: Wrong results for different characters

The JMP support has answered me, it may be a defect which I have found.

 

Their support gave me the following solution to my original problem to remove unneeded items from a list using the Associative Array function:

 

filtered list = {"b", 1, 2, 3};
na_list = {"b"};
result = Associative Array(filtered list) << Remove(Associative Array(na_list)) << Get Keys; // {1, 2, 3}