cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%E6%9B%B4%E6%96%B0%E4%BD%9C%E7%82%BA%E9%A1%9E%E5%88%A5%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8%E7%9A%84%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%EF%BC%8C%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%E9%A1%9E%E5%88%A5%E8%AE%8A%E9%87%8F%EF%BC%8C%E5%AE%83%E6%98%AF%E4%B8%80%E5%80%8B%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%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%E4%BD%86%E6%98%AF%E7%95%B6%E6%88%91%E5%91%BC%E5%8F%AB%E6%AD%A4%E9%A1%9E%E4%BE%86%E6%9B%B4%E6%96%B0%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%E6%99%82%EF%BC%8C%E8%A9%B2%E6%95%B8%E7%B5%84%E4%BB%8D%E7%84%B6%E6%98%AF%E7%A9%BA%E7%9A%84%E3%80%82%E6%9C%89%E4%BB%80%E9%BA%BC%E6%83%B3%E6%B3%95%E5%97%8E%EF%BC%9F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E9%82%84%E5%80%BC%E5%BE%97%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%EF%BC%8C%E6%88%91%E5%9C%A8%E9%A1%9E%E5%88%A5%E5%A4%96%E9%83%A8%E6%B8%AC%E8%A9%A6%E4%BA%86%E6%AD%A4%E8%AA%9E%E6%B3%95%E4%BB%A5%E6%9B%B4%E6%96%B0%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%EF%BC%8C%E4%B8%A6%E4%B8%94%E5%AE%83%E7%9A%84%E8%A1%8C%E7%82%BA%E7%AC%A6%E5%90%88%E9%A0%90%E6%9C%9F%E3%80%82%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%E8%87%AA%E5%8B%95%E5%8C%96%E5%92%8C%E8%85%B3%E6%9C%AC%E7%B7%A8%E5%AF%AB%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%E8%A6%96%E7%AA%97%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%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E6%9B%B4%E6%96%B0%E4%BD%9C%E7%82%BA%E9%A1%9E%E5%88%A5%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8%E7%9A%84%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%88%91%E6%83%B3%E4%BD%A0%E5%8F%AF%E8%83%BD%E6%83%B3%E6%B7%BB%E5%8A%A0%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%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%E9%80%99%E6%98%AF%E4%B8%8D%E5%BF%85%E8%A6%81%E7%9A%84%EF%BC%8C%E6%88%91%E4%B8%8D%E7%A2%BA%E5%AE%9A%E6%98%AF%E5%90%A6%E6%87%89%E8%A9%B2%E4%BD%BF%E7%94%A8%E5%AE%83%EF%BC%88%E4%BD%86%E9%80%99%E8%A3%A1%E4%BD%BF%E7%94%A8%E5%AE%83%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%E3%80%82shtml%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%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E6%9B%B4%E6%96%B0%E4%BD%9C%E7%82%BA%E9%A1%9E%E5%88%A5%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8%E7%9A%84%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777788%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%EF%BC%8C%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E6%89%80%E4%BB%A5%EF%BC%8C%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%20init%20%E6%96%B9%E6%B3%95%E3%80%82%E6%88%91%E6%B2%92%E6%9C%89%E6%8A%8A%E7%8F%AD%E7%B4%9A%E7%9A%84%E6%95%B4%E5%80%8B%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B%E9%83%BD%E6%8B%BF%E5%87%BA%E4%BE%86%E6%98%AF%E5%87%BA%E6%96%BC%E6%87%B6%E6%83%B0%E3%80%82%E6%88%91%E8%AA%8D%E7%82%BA%E6%B2%92%E6%9C%89%E5%BF%85%E8%A6%81%E8%A7%A3%E6%B1%BA%E9%80%99%E5%80%8B%E5%95%8F%E9%A1%8C%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E6%9B%B4%E6%96%B0%E4%BD%9C%E7%82%BA%E9%A1%9E%E5%88%A5%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8%E7%9A%84%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E4%BD%86%E6%98%AF%EF%BC%8C%E7%94%A8%3CEM%3Ethis%3Aarray%3C%2FEM%3E%E5%AF%A6%E4%BE%8B%E5%8C%96%E8%AE%8A%E6%95%B8%E4%BC%BC%E4%B9%8E%E6%9C%89%E6%95%88%E3%80%82%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E7%82%BA%E4%BB%80%E9%BA%BC%E9%80%99%E6%9C%83%E7%94%A2%E7%94%9F%E5%BD%B1%E9%9F%BF%EF%BC%9F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777814%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E5%9B%9E%E8%A6%86%EF%BC%9A%E6%9B%B4%E6%96%B0%E4%BD%9C%E7%82%BA%E9%A1%9E%E5%88%A5%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8%E7%9A%84%E9%97%9C%E8%81%AF%E6%95%B8%E7%B5%84%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%3E%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20Define%20Class%3C%2FA%3E%E5%8F%AF%E8%83%BD%E6%9C%83%E7%B5%A6%E5%87%BA%E4%B8%80%E4%BA%9B%E8%A7%A3%E9%87%8B%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