cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
ThomasZatValcon
Level III

JMP 15 assumes that an l-value in jsl is a column name - is this intended?

JMP 15 assumes an l-value is a column name. This was not the behavior in earlier versions. Is this intended or is it a bug?

 

To reproduce:

dt=new  table("test");
dt<<new column("a");
a=1;

This gives an error in JMP 15 but not in JMP 14.

7 REPLIES 7
txnelson
Super User

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

When I startup new sessions in JMP 14.3 and JMP 15.1 and run your script, I get the same error in both versions

Cannot set value for the column 'a' because the row number (0) is not valid.
Jim
ThomasZatValcon
Level III

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

Interesting. When I run it in 14.3.0 I do not get the error. I do not have earlier versions installed.

David_Burnham
Super User (Alumni)

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

you need 

names default to here(1);

it's annoying - I don't know if it is intentional; I would prefer it if variables were only scoped as column name if prefixed with a colon (i.e. :a).

-Dave
Craige_Hales
Super User

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

I think the behavior depends if global:a already exists. It is annoying. 

Craige
lwx228
Level VIII

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

I also ran this incorrectly in version 14.3.

2020-07-01_09-24.png
The only way to avoid this error is to remember that the variable name cannot be the same as the column name.

 

txnelson
Super User

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

@lwx228  is incorrect.  One can have a variable and a column with the same name.  It is actually just a matter of scoping the name correctly, so JMP knows which you are talking about

Take the following script

dt=new table("Example", new column("A") );
dt << add rows(1);

a = 13;
:: a =47;
:a[1] = a;

show(a,::a,:a[1],dt:a[1]);

It results in

a = 47;
a = 47;
:A[1] = 47;
dt:a[1] = 47;

What is going on here is that actually, all variables and columns have a 2 part name, separated by a colon ":"

namespace:name

and by default, if only a name is given such as in the assignment statement

a = 13;

it is assumed that "a" is a variable.  If a colon is placed in front of the variable name,

:a[1] = a;

it is assumed one is referring to a column.  In the above example the 1st row in the column named "a" will be given the current value (13) of the variable named "a".

One can also provide the complete 2 part name for a variable and a column. 

For variables, the default namespace (first part of the name) is called ":".  That's right, a colon, so the full proper name for the variable "a" is

::a

you can see the results of using the full name in the Show() statement and it's results

The full proper name for a column in this little script, is made up of the pointer variable assigned to the data table, and the actual data table column name

dt:a

The Show() statement also illustrates the 2 part name usage for a column

 

I hope this has not just confused everyone, but instead has given some insight

Jim
ThomasZatValcon
Level III

Re: JMP 15 assumes that an l-value in jsl is a column name - is this intended?

Hi txnelson

 

Thanks for the great explanation. Had not thought about the first : in :: to refer to the global namespace. I must have been wrong with 14.3. When I try now, I get the warning too.

 

You wrote "and by default, if only a name is given such as in the assignment statement".

 

This is also what I expected, but if a column in a data table has the same name, JMP clearly assumes it should assign the value to the  column.

 

Seems names default to here(1) fixes that behaviour as David pointed out. I always waited with defaulting names to the here namespace because it makes debugging more cumbersome. But from now on, I will always use this option from the start!

 

I hope the JMP team will change that behaviour, because it can create some really hard to find bugs! Especially, if a script actually refers to columns without :'s !