cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
hogi
Level XI

Does Head evaluate its argument?

From Using JSL to Develop Efficient, Robust Applications (EU 2018 415), I learned that there are some functions which evaluate their argument and others which don't:

 

hogi_0-1709477067669.png

 

I wondered about Head. Here everything looks logic ...

f= Expr(x=2);
Substitute(NameExpr(f),Expr(x), Expr(y));
Head(f);

Head is not like Substitute, I can directly use the function name as an argument  - and Head returns the head of the expression: Assign() 

 

After checking some other functions which "don't evaluate their argument":

Expr(x=2); // x=2
Name Expr(x=2); // x=2

let's check the result for

Head(x=2)

which is "2" - i.e. the result after evaluating the argument?!?! why is it not assign()?

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Does Head evaluate it's argument?

jthi_0-1709482989532.png

Names Default To Here(1);
{a, b, c} = {1, 2, 3};

Head(Expr(Sum(a, b, c)));
HeadExpr(Sum(a, b, c)); // Deprecated

Head(Sum(a, b, c));

https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-expressions-macros-and-lists.shtml#

jthi_1-1709483106946.png

 

-Jarmo

View solution in original post

hogi
Level XI

Re: Does Head evaluate it's argument?

ah, ok, the scripting index is very clear.

 

In general, it could make scripting a lot easier if the JSL editor used some highlighting to distinguish between arguments that are evaluated and arguments that aren't evaluated before the function is executed:

Advanced syntax highlighting in JSL Editor

 


more wishes [2024-03]: myWishes.jmp 

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Does Head evaluate it's argument?

jthi_0-1709482989532.png

Names Default To Here(1);
{a, b, c} = {1, 2, 3};

Head(Expr(Sum(a, b, c)));
HeadExpr(Sum(a, b, c)); // Deprecated

Head(Sum(a, b, c));

https://www.jmp.com/support/help/en/17.2/#page/jmp/advanced-expressions-macros-and-lists.shtml#

jthi_1-1709483106946.png

 

-Jarmo
hogi
Level XI

Re: Does Head evaluate it's argument?

ah, ok, the scripting index is very clear.

 

In general, it could make scripting a lot easier if the JSL editor used some highlighting to distinguish between arguments that are evaluated and arguments that aren't evaluated before the function is executed:

Advanced syntax highlighting in JSL Editor

 


more wishes [2024-03]: myWishes.jmp 

hogi
Level XI

Re: Does Head evaluate it's argument?

same for Narg - the argument gets evaluated (1x, like with Name Expr()
(adapted from the scripting guide)

aExpr = {a+b,c,d,e+f+g};
Show(NArg(aExpr)); //4 Show(NArg(Arg(aExpr,4))); // 3 Show(NArg(Add(1,2,3,4))); // 0 Show(NArg(Expr(Add(1,2,3,4)))); //4 Show(Head(aExpr)); //List() Show(Head(Arg(aExpr,4))); // Add() Show(Head(Add(1,2,3,4))); // 10 Show(Head(Expr(Add(1,2,3,4)))); //Add