Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted

JMP class methods treat arguments as class members

Hi Staff

I wanted to start using JMP classes in scripting, but ran into an unfortunate behaviour: When giving arguments to a method, the arguments are treated as if they were class members, which makes classes almost unusable as the argument to the method depends on if a class member already uses that variable. I found no way to force sending a global or here: variable to the method. I believe it to be a bug. The following code reproduces this behaviour:

 

define class ("aClass",
	varA = .;
	aMethod=method({someVar},
		varA = someVar;
		show(someVar);
	)
);

obj=new object(aClass());

varB=3;
obj:aMethod(varB);

varA=4;
obj:aMethod(varA);
obj:aMethod(::varA);

In the above, because varA is both a global variable and a metod variable, "aMethod" just gets 3 and not 4 in the argument. So behaviour is influenced by interaction between internal class member names and global variable names.

 

Kind regards,

Thomas

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Craige_Hales
Staff (Retired)

Re: JMP class methods treat arguments as class members

I agree, it does look like a bug. @EvanMcCorkle @audrey_shull 

A workaround is to prefix the member variable names with m_ . I've used that prefix, or a variation, for a long time to help anyone reading the code understand when they are looking at a member variable. 

Craige

View solution in original post

2 REPLIES 2
Highlighted
Craige_Hales
Staff (Retired)

Re: JMP class methods treat arguments as class members

I agree, it does look like a bug. @EvanMcCorkle @audrey_shull 

A workaround is to prefix the member variable names with m_ . I've used that prefix, or a variation, for a long time to help anyone reading the code understand when they are looking at a member variable. 

Craige

View solution in original post

Highlighted
Craige_Hales
Staff (Retired)

Re: JMP class methods treat arguments as class members

And a couple of posts using classes:

How to use Define Class 

Functional programming using JSL objects 

Craige
Article Labels