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%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E5%A4%89%E6%95%B0%E3%81%A7%E3%81%82%E3%82%8B%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777763%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E3%80%81%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%81%A7%E3%81%82%E3%82%8B%E3%82%AF%E3%83%A9%E3%82%B9%E5%A4%89%E6%95%B0%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%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%E3%81%97%E3%81%8B%E3%81%97%E3%80%81%E3%81%93%E3%81%AE%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%97%E3%81%A6%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%E3%81%A8%E3%80%81%E9%85%8D%E5%88%97%E3%81%AF%E3%81%BE%E3%81%A0%E7%A9%BA%E3%81%AE%E3%81%BE%E3%81%BE%E3%81%A7%E3%81%99%E3%80%82%E4%BD%95%E3%81%8B%E3%81%94%E6%84%8F%E8%A6%8B%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%8B%3F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E3%81%BE%E3%81%9F%E3%80%81%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AB%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AE%E5%A4%96%E9%83%A8%E3%81%A7%E3%81%93%E3%81%AE%E6%A7%8B%E6%96%87%E3%82%92%E3%83%86%E3%82%B9%E3%83%88%E3%81%97%E3%81%9F%E3%81%A8%E3%81%93%E3%82%8D%E3%80%81%E6%9C%9F%E5%BE%85%E3%81%A9%E3%81%8A%E3%82%8A%E3%81%AB%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%9F%E3%81%93%E3%81%A8%E3%82%82%E6%B3%A8%E7%9B%AE%E3%81%AB%E5%80%A4%E3%81%97%E3%81%BE%E3%81%99%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%E3%81%A8%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%E3%82%BA%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%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E5%A4%89%E6%95%B0%E3%81%A7%E3%81%82%E3%82%8B%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777786%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E5%88%9D%E6%9C%9F%E5%8C%96%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%97%E3%81%9F%E6%96%B9%E3%81%8C%E8%89%AF%E3%81%84%E3%81%A8%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%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%E3%81%93%E3%82%8C%E3%81%AF%E5%BF%85%E9%A0%88%E3%81%A7%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%81%97%E3%80%81%E4%BD%BF%E7%94%A8%E3%81%99%E3%81%B9%E3%81%8D%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B%E3%82%82%E3%82%8F%E3%81%8B%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%20(%E3%81%9F%E3%81%A0%E3%81%97%E3%80%81%E3%81%93%E3%81%93%E3%81%A7%E3%81%AF%E4%BD%BF%E7%94%A8%E3%81%95%E3%82%8C%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%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.shtml%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%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E5%A4%89%E6%95%B0%E3%81%A7%E3%81%82%E3%82%8B%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777788%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E3%80%81%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E3%81%A0%E3%81%8B%E3%82%89%E3%80%81init%20%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%82%92%E7%94%A8%E6%84%8F%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%E6%80%A0%E6%83%B0%E3%81%8B%E3%82%89%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AE%E3%83%AF%E3%83%BC%E3%82%AF%E3%83%95%E3%83%AD%E3%83%BC%E5%85%A8%E4%BD%93%E3%82%92%E7%9C%81%E7%95%A5%E3%81%97%E3%81%9F%E3%82%8F%E3%81%91%E3%81%A7%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%E5%95%8F%E9%A1%8C%E3%81%AE%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%81%AF%E5%BF%85%E8%A6%81%E3%81%AA%E3%81%84%E3%81%A8%E8%80%83%E3%81%88%E3%81%BE%E3%81%97%E3%81%9F%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%3ERe%3A%20%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E5%A4%89%E6%95%B0%E3%81%A7%E3%81%82%E3%82%8B%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777790%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%97%E3%81%8B%E3%81%97%E3%80%81%20%3CEM%3Ethis%3Aarray%3C%2FEM%3E%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E5%A4%89%E6%95%B0%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%82%BF%E3%83%B3%E3%82%B9%E5%8C%96%E3%81%99%E3%82%8B%E3%81%A8%E3%80%81%E3%81%86%E3%81%BE%E3%81%8F%E3%81%84%E3%81%A3%E3%81%9F%E3%82%88%E3%81%86%E3%81%A7%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E3%81%AA%E3%81%9C%E3%81%93%E3%82%8C%E3%81%8C%E9%81%95%E3%81%84%E3%82%92%E7%94%9F%E3%82%80%E3%81%AE%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%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%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%90%E3%83%AB%E5%A4%89%E6%95%B0%E3%81%A7%E3%81%82%E3%82%8B%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%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%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%81%AF%E3%80%81%3C%2FA%3E%E8%AA%AC%E6%98%8E%E3%81%8C%E3%81%82%E3%82%8B%E3%81%8B%E3%82%82%E3%81%97%E3%82%8C%E3%81%BE%E3%81%9B%E3%82%93%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