JMP has a string data type:
a = "cat";
b = "3 + 5";
a and b are strings. B looks like an expression, but is not.
c = parse( b );
c is an expression, which can be shown as a tree:
operator(+)
/ \
3 5
c = expr( 3 + 5 ); // is another way to get the same expression stored in c
d = eval( c ); // or just d = c; the right hand side is evaluated anyway
d is 8.
Sometimes JMP will automatically evaluate c to 8, sometimes not. Sometimes you want 8, sometimes you want 3+5.
e = nameexpr(c);
e gets the expression that c holds; think of nameexpr as a thin wrapper; when the wrapper is evaluated it blocks a deeper evaluation and returns the 3+5 expression, unevaluated, rather than 8.
JMP also has a set of functions for manipulating an expression tree, not covered here. @jthi used substitute, for example.
I think part of what you are puzzling over is the difference between the way different functions in JSL will handle an expression argument:
cos(c) , like most functions, will evaluate c to 8. This is what you expect.
colname<<setformula( c ) literally copies the expression (c, not 3+5, not 8 ) to the column formula without evaluating it. (Just as it would for <<setformula(col1 + col2), which is what you want. Not like the cos() function.)
So setformula has two special cases:
colname<<setformula( c ) --> c (not special)
colname<<setformula( eval(c) ) --> 8 (eval wrapper)
colname<<setformula( nameexpr(c) ) --> 3+5 (nameexpr wrapper)
Note that these are indeed special cases; setformula makes an extra effort to detect the eval or nameexpr wrapper to make the JSL do what you expect.
Now that I'm nearly done I wish I'd used x+y rather than 3+8 for part of this; it would be more clear why you might want to postpone the evaluation to a later point in time. Also, even a single number like 8 is an expression; eval(8) is 8.
Craige