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?
dt=new table("test"); dt<<new column("a"); a=1;
This gives an error in JMP 15 but not in JMP 14.
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.
Interesting. When I run it in 14.3.0 I do not get the error. I do not have earlier versions installed.
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).
I think the behavior depends if global:a already exists. It is annoying.
I also ran this incorrectly in version 14.3.
The only way to avoid this error is to remember that the variable name cannot be the same as the column name.
@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 = a; show(a,::a,:a,dt:a);
It results in
a = 47; a = 47; :A = 47; dt:a = 47;
What is going on here is that actually, all variables and columns have a 2 part name, separated by a colon ":"
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 = 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
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
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
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 !