cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
rbeeman
Level I

Passing Variables Passes the Variable Name Instead of Variable Value

Using JMP 15.2.1.

I think I must have a misunderstanding of how variables work in JSL.I have run into this issue a few times, and would finally like to understand what I am doing wrong.

I have a function in which I do some calculations, store the results in variables, and then attempt to insert the results into a list. I know that the variables contain the values I want them to, but when I attempt to add them to the list it adds the variable name to the list instead of the value of the variable. Because these are locally defined variables, this then causes errors outside the scope of that function.

I have tried using Eval/Eval List anywhere I can think of but that is not working either.

How can I make the returned list contain the values within the variables.

Thanks in advance!

list = {{3,4}, {1,5}, {3,2}};
deltaX = 1;
deltaY = 2;

updateList = Function({cl, dx, dy},
	{newX, newY},
	
	newX = cl[1][1] + dx;
	newY = cl[1][2] + dy;
	show(newX);
	
	Insert Into(cl, {{newX, newY}}, 1);
	
	show(cl);
	return(cl);
);

list2 = updateList(list, deltaX, deltaY);
show(list2);
//this errors because list2[1][1] contains newX instead of the value 4
//list2[1][1] + 1;




 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Passing Variables Passes the Variable Name Instead of Variable Value

A list like { x, y } contains the names of the variables, not their values. Some JSL functions will dig the values out; line( {x1, y1}, {x2, y2} ) for example.

The EvalList function accepts a list with expressions, maybe as simple as a variable name, evaluates them and returns a new list, { 3, 4 }.

The Insert Into function notices the value it is inserting is a list and unpacks the list to get the elements to insert. That's why you have a list with one element that is another list of two elements: you want to insert the two element list without unpacking it, so you wrap it in a list.

But now you have to figure out how to do the eval list on the inner list of the nested list. You can do it, with something like this:

x=3;
y=4;
evallist({evallist({x,y})}) // {{3, 4}}

Here's a shortcut that is easier or harder to understand

x=3;
y=4;
aslist(x||y) // {{3, 4}}

AsList upacks the matrix into a list and makes a list of lists of row elements; the || concatenation operator puts two (or more) numbers together into a row matrix.

 

Craige

View solution in original post

2 REPLIES 2
Craige_Hales
Super User

Re: Passing Variables Passes the Variable Name Instead of Variable Value

A list like { x, y } contains the names of the variables, not their values. Some JSL functions will dig the values out; line( {x1, y1}, {x2, y2} ) for example.

The EvalList function accepts a list with expressions, maybe as simple as a variable name, evaluates them and returns a new list, { 3, 4 }.

The Insert Into function notices the value it is inserting is a list and unpacks the list to get the elements to insert. That's why you have a list with one element that is another list of two elements: you want to insert the two element list without unpacking it, so you wrap it in a list.

But now you have to figure out how to do the eval list on the inner list of the nested list. You can do it, with something like this:

x=3;
y=4;
evallist({evallist({x,y})}) // {{3, 4}}

Here's a shortcut that is easier or harder to understand

x=3;
y=4;
aslist(x||y) // {{3, 4}}

AsList upacks the matrix into a list and makes a list of lists of row elements; the || concatenation operator puts two (or more) numbers together into a row matrix.

 

Craige
rbeeman
Level I

Re: Passing Variables Passes the Variable Name Instead of Variable Value

Thanks for the explanation! Using the double evallist worked for me.