cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
%3CLINGO-SUB%20id%3D%22lingo-sub-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%A0%84%EC%97%AD%20%EB%B3%80%EC%88%98%EC%9D%B8%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94%2C%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%B8%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EB%B3%80%EC%88%98%EA%B0%80%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edefine%20class%20(%0A%22class%20name%22%2C%0A%0Aass_array%20%20%3D%20associative%20array%20()%3B%0A%0Ameth1%20%3D%20method(%7Bx%2Cy%7D%2C%0Afor(i%20%3D%201%2C%20n%20%26lt%3B%3D%20n%20items(x)%2Ci%2B%2B%0Axi%20%3D%20x%5Bi%5D%3B%0Ayi%20%3D%20y%5Bi%5D%3B%0Atry(%0Aass_array%20%20%26lt%3B%26lt%3B%20insert(xi%2C%20Insert(eval%20list(ass_array%5Beval(xi)%5D)%2C%20eval(yi)))%2C%0Aass_array%20%20%26lt%3B%26lt%3B%20insert(xi%2C%20List(eval(yi)))%0A)%3B%0A%0A)%3B%0A%0A%0A)%3B%0A%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%ED%95%98%EC%A7%80%EB%A7%8C%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%98%EA%B8%B0%20%EC%9C%84%ED%95%B4%20%EC%9D%B4%20%ED%81%B4%EB%9E%98%EC%8A%A4%EB%A5%BC%20%ED%98%B8%EC%B6%9C%ED%95%98%EB%A9%B4%20%EB%B0%B0%EC%97%B4%EC%9D%B4%20%EC%97%AC%EC%A0%84%ED%9E%88%20%EB%B9%84%EC%96%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EC%9D%B4%EA%B2%AC%EC%9E%88%EB%8A%94%20%EC%82%AC%EB%9E%8C%3F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%98%EA%B8%B0%20%EC%9C%84%ED%95%B4%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%99%B8%EB%B6%80%EC%97%90%EC%84%9C%20%EC%9D%B4%20%EA%B5%AC%EB%AC%B8%EC%9D%84%20%ED%85%8C%EC%8A%A4%ED%8A%B8%ED%96%88%EC%9C%BC%EB%A9%B0%20%EC%98%88%EC%83%81%EB%8C%80%EB%A1%9C%20%EC%9E%91%EB%8F%99%ED%96%88%EB%8B%A4%EB%8A%94%20%EC%A0%90%EB%8F%84%20%EC%A3%BC%EB%AA%A9%ED%95%A0%20%EA%B0%80%EC%B9%98%EA%B0%80%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3E%EC%9E%90%EB%8F%99%ED%99%94%20%EB%B0%8F%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8C%85%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%EC%9C%88%EB%8F%84%EC%9A%B0%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%A0%84%EC%97%AD%20%EB%B3%80%EC%88%98%EC%9D%B8%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%EC%B4%88%EA%B8%B0%ED%99%94%20%EB%B0%A9%EB%B2%95%EC%9D%84%20%EC%B6%94%EA%B0%80%ED%95%98%EA%B3%A0%20%EC%8B%B6%EC%9D%84%20%EC%88%98%EB%8F%84%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0A%0ADefine%20Class(%22class%20name%22%2C%0A%09ass_array%20%3D%20Associative%20Array()%3B%0A%09%0A%09_init_%20%3D%20Method(%7B%7D%2C%0A%09%09this%3Aass_array%20%3D%20ass_array%3B%0A%09)%3B%0A%09%0A%09meth1%20%3D%20Method(%7Bx%2C%20y%7D%2C%0A%09%09ass_array%20%3D%20Associative%20Array()%3B%0A%0A%09%09For(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(x)%2C%20i%2B%2B%2C%0A%09%09%09xi%20%3D%20x%5Bi%5D%3B%0A%09%09%09yi%20%3D%20y%5Bi%5D%3B%0A%09%09%09Try(%0A%09%09%09%09ass_array%20%26lt%3B%26lt%3B%20Insert(xi%2C%20Insert(Eval%20List(ass_array%5BEval(xi)%5D)%2C%20Eval(yi)))%2C%0A%09%09%09%09ass_array%20%26lt%3B%26lt%3B%20Insert(xi%2C%20List(Eval(yi)))%0A%09%09%09)%3B%0A%09%09)%3B%0A%09)%3B%0A)%3B%0A%0Acn%20%3D%20New%20Object(%22class%20name%22)%3B%0A%0Ashow(cn%3Aass_array)%3B%0Acn%3Ameth1(%7B%22a%22%2C%20%22b%22%7D%2C%20%7B%22c%22%2C%20%22d%22%7D)%3B%0Ashow(cn%3Aass_array)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%EC%9D%B4%EA%B2%83%EC%9D%80%20%ED%95%84%EC%9A%94%ED%95%98%EC%A7%80%20%EC%95%8A%EC%9C%BC%EB%A9%B0%20%EC%82%AC%EC%9A%A9%ED%95%B4%EC%95%BC%20%ED%95%98%EB%8A%94%EC%A7%80%20%EC%9E%98%20%EB%AA%A8%EB%A5%B4%EA%B2%A0%EC%8A%B5%EB%8B%88%EB%8B%A4(%EA%B7%B8%EB%9F%AC%EB%82%98%20%EC%97%AC%EA%B8%B0%EC%97%90%EC%84%9C%EB%8A%94%20%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F18.0%2F%23page%2Fjmp%2Fadvanced-classes.shtml%23ww761769%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F18.0%2F%23page%2Fjmp%2Fadvanced-classes%EC%97%90%EC%84%9C%20%EC%82%AC%EC%9A%A9%EB%90%A9%EB%8B%88%EB%8B%A4.%20shtml%23ww761769%3C%2FA%3E%20)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777788%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%A0%84%EC%97%AD%20%EB%B3%80%EC%88%98%EC%9D%B8%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777788%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94%2C%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EA%B7%B8%EB%9E%98%EC%84%9C%20init%20%EB%A9%94%EC%86%8C%EB%93%9C%EA%B0%80%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%82%98%EB%8A%94%20%EA%B2%8C%EC%9C%BC%EB%A6%84%20%EB%95%8C%EB%AC%B8%EC%97%90%20%EC%88%98%EC%97%85%EC%9D%98%20%EC%A0%84%EC%B2%B4%20%ED%9D%90%EB%A6%84%EC%9D%84%20%EB%91%90%EC%A7%80%20%EC%95%8A%EC%95%98%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%AC%B8%EC%A0%9C%EB%A5%BC%20%ED%95%B4%EA%B2%B0%ED%95%98%EB%8A%94%20%EA%B2%83%EC%9D%B4%20%ED%95%84%EC%9A%94%ED%95%98%EB%8B%A4%EA%B3%A0%20%EC%83%9D%EA%B0%81%ED%95%98%EC%A7%80%20%EC%95%8A%EC%95%98%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%A0%84%EC%97%AD%20%EB%B3%80%EC%88%98%EC%9D%B8%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%EA%B7%B8%EB%9F%AC%EB%82%98%20%3CEM%3Ethis%3Aarray%EB%A5%BC%3C%2FEM%3E%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%B3%80%EC%88%98%EB%A5%BC%20%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4%ED%99%94%ED%95%98%EB%8A%94%20%EA%B2%83%EC%9D%80%20%ED%9A%A8%EA%B3%BC%EA%B0%80%20%EC%9E%88%EC%97%88%EB%8D%98%20%EA%B2%83%20%EA%B0%99%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EC%9D%B4%EA%B2%83%EC%9D%B4%20%EC%99%9C%20%EC%B0%A8%EC%9D%B4%EB%A5%BC%20%EB%A7%8C%EB%93%9C%EB%8A%94%EA%B0%80%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777814%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%ED%81%B4%EB%9E%98%EC%8A%A4%20%EC%A0%84%EC%97%AD%20%EB%B3%80%EC%88%98%EC%9D%B8%20%EC%97%B0%EA%B4%80%20%EB%B0%B0%EC%97%B4%EC%9D%84%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777814%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FUncharted%2FHow-to-use-Define-Class%2Fm-p%2F274410%23U274410%22%20class%3D%22lia-mention-container-editor-message%20lia-img-icon-blog-thread%20lia-fa-icon%20lia-fa-blog%20lia-fa-thread%20lia-fa%22%20target%3D%22_blank%22%3EDefine%20Class%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%97%90%20%EB%8C%80%ED%95%9C%3C%2FA%3E%20%EC%84%A4%EB%AA%85%EC%9D%B4%20%EC%A0%9C%EA%B3%B5%EB%90%A0%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
doctorfizz
Level II

Update an Associative array that is a class global variable

Hello,

 

I have a class variable that is an associative array

 

define class (
"class name",

ass_array  = associative array ();

meth1 = method({x,y},
for(i = 1, n <= n items(x),i++
xi = x[i];
yi = y[i];
try(
ass_array  << insert(xi, Insert(eval list(ass_array[eval(xi)]), eval(yi))),
ass_array  << insert(xi, List(eval(yi)))
);

);


);

);

but when I call this class to update the associative array, the array is still empty. Any thoughts? 

 

It is also worth noting that I tested this syntax external to the class to update an associative array and it acted as expected. 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Update an Associative array that is a class global variable

I think you might want to add initialization method

Names Default To Here(1);


Define Class("class name",
	ass_array = Associative Array();
	
	_init_ = Method({},
		this:ass_array = ass_array;
	);
	
	meth1 = Method({x, y},
		ass_array = Associative Array();

		For(i = 1, i <= N Items(x), i++,
			xi = x[i];
			yi = y[i];
			Try(
				ass_array << Insert(xi, Insert(Eval List(ass_array[Eval(xi)]), Eval(yi))),
				ass_array << Insert(xi, List(Eval(yi)))
			);
		);
	);
);

cn = New Object("class name");

show(cn:ass_array);
cn:meth1({"a", "b"}, {"c", "d"});
show(cn:ass_array);

this isn't necessary and I'm not sure if it should even be used (but it is used here https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-classes.shtml#ww761769)

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Update an Associative array that is a class global variable

I think you might want to add initialization method

Names Default To Here(1);


Define Class("class name",
	ass_array = Associative Array();
	
	_init_ = Method({},
		this:ass_array = ass_array;
	);
	
	meth1 = Method({x, y},
		ass_array = Associative Array();

		For(i = 1, i <= N Items(x), i++,
			xi = x[i];
			yi = y[i];
			Try(
				ass_array << Insert(xi, Insert(Eval List(ass_array[Eval(xi)]), Eval(yi))),
				ass_array << Insert(xi, List(Eval(yi)))
			);
		);
	);
);

cn = New Object("class name");

show(cn:ass_array);
cn:meth1({"a", "b"}, {"c", "d"});
show(cn:ass_array);

this isn't necessary and I'm not sure if it should even be used (but it is used here https://www.jmp.com/support/help/en/18.0/#page/jmp/advanced-classes.shtml#ww761769)

-Jarmo
doctorfizz
Level II

Re: Update an Associative array that is a class global variable

Hello,

 

so, I have an init method. I did not put the entire workflow of the class out of laziness. I did not think it was necessary to troubleshoot the problem. 

doctorfizz
Level II

Re: Update an Associative array that is a class global variable

But, instantiating the variable with the this:array seemed to have worked.

 

Why does this make a difference? 

jthi
Super User

Re: Update an Associative array that is a class global variable

How to use Define Class might give some explanation

-Jarmo