cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to see how to import and prepare Excel data on Jan. 30 from 2 to 3 p.m. ET.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hogi
Level XIII

Indexing the return value of a function

Today's challenge:

f=Function({}, {1,2,3});

tmp=f();
y=tmp[1]; // works

x=f()[1] // doesn't work


understanding the issue helps a lot to understand how JSL works  : - )

2 REPLIES 2
hogi
Level XIII

Re: Indexing the return value of a function

the inverse problem:

names default to here(1);
x=1;
Eval(x=1); // "does the same"

x= Expr(hello);
Eval(x= Expr(hello)); // fails
hogi
Level XIII

Re: Indexing the return value of a function

Does Head evaluate its argument? 

concerning assign:
1. arg: no
2. arg: yes

If you need to evaluate an expression "manually" [before taking the fist item from the result], use Eval():

x=f()[1] // doesn't work
x=Eval(f())[1] // works

concerning glue:
any args: yes

.... and Eval:
yes, of course!

besides that, there is an additional evaluation of the return value *) - after a first evaluation of the argument. So

Eval(print(1);x= Expr(hello);print(x); Expr(print(2)));

correctly assigns x=Expr(hello) and prints:

hogi_0-1769516471823.png

*) -> link / documentation / community?

Recommended Articles