JMP Expr() weirdness, can anyone explain?This is mostly just a frustration post over the following inconsistency with inserting 'IF' expressions into an 'IF' expression. It is my understanding that programming languages should be nothing if not consistent (and I'm aware of many other JMP inconsistencies -- it's just that this one makes no sense to me at all).
/*
What I want is to generate an expression such as the one below programmatically. There of course is a straight-forward work around, I just don't like dealing with special cases especially when they make no sense.
Expr( If( a, If( b, c) ) )<BR />
*/
expr = Expr( If( a ) );
Insert Into( expr, Expr( If( b, c ) ) );
Show( Name Expr( expr ) );
/*
If( a, b, c)
*/
expr = Expr( not an If( a ) );
Insert Into( expr, Expr( If( b, c ) ) );
Show( Name Expr( expr ) );
/*
not an If( a, If( b, c) )
*/
If anyone has any insights, or especially if you know of a way to reliably insert any expression into any other expression (not by using 'Eval Insert' or strings), that would be great! Thanks!
Advanced Statistical ModelingRe: JMP Expr() weirdness, can anyone explain?there is a workaround to accomplish the requested task - but the actual question: WHY?!? is not yet answered.
added to Tiny Traps in Jmp and JSL
Re: JMP Expr() weirdness, can anyone explain?Further examples which easily disprove some of the hypotheses - and add some further insights:
expr = Expr( If( a, x ) );
Insert Into( expr, Expr(If( b,c )) );
Show( Name Expr( expr ) ); // if(a,x,b,c)
expr = Expr( If( a ) );
Insert Into( expr, Expr(If( b )) );
Show( Name Expr( expr ) ); // if(a,b)
expr = Expr( List( a ) );
Insert Into( expr, Expr(List( b )) );
Show( Name Expr( expr ) ); // List(a,b)
expr = Expr( Graph Builder( a ) );
Insert Into( expr, Expr(Graph Builder ( b )) );
Show( Name Expr( expr ) ); // Graph Builder(a,b)
expr = Expr( Head( a ) );
Insert Into( expr, Expr(Head( b )) );
Show( Name Expr( expr ) ); // Head(a,b) (!)
expr = Expr( Not( a ) );
Insert Into( expr, Expr(Not( b )) );
Show( Name Expr( expr ) ); // Not(a) (!!)
Re: JMP Expr() weirdness, can anyone explain?Hello,
Although I am unsure, I wonder if this behavior is because the snippet "IF ( a )" is not a well-formed JSL expression. That is, the function IF takes 2 arguments, not one. JMP has no way of knowing whether "notAnIf( a )" is a well-formed expression, so perhaps shrugs its shoulders and proceeds ( ? ) Total guess on my part.
The fact the following works as you intend seems to add some support to this idea, but this does not explain why@ben_ph 's idea works, as it successfully inserts REPLACE_ME where I've got a missing.
expr = Expr( If( a, . ) );
Substitute Into( expr, expr(.), expr( If( b, c ) ) );
Show( Name Expr( expr ) );

Cheers,
Brady
Re: JMP Expr() weirdness, can anyone explain?As a workaround without using strings you could do something like
expr = Expr( If( a ) );
Insert Into( expr, Expr( REPLACE_ME ) );
Substitute Into( expr, Expr( REPLACE_ME ), Expr( If( b, c ) ) );
Name Expr( expr );
// If( a, If( b, c ) )
Re: JMP Expr() weirdness, can anyone explain?This is closely related to the same as How to insert a list into another list . With your question, I now suspect there is a special exception for builtin function names that shows this behavior.
expr = Expr( not an If( a ) );
is the same as
expr = Expr( NotAnIf( a ) );
making NotAnIf (or not an if) be a function name JMP doesn't recognize as builtin. In the { list } example, {...} is the same as List(...) and is a builtin function name.
expr = Expr( sum( a ) );
Insert Into( expr, Expr( sum( b, c ) ) );
Show( Name Expr( expr ) );
/*:
Name Expr(expr) = Sum(a, b, c);
//:*/
expr = Expr( sum1( a ) );
Insert Into( expr, Expr( sum1( b, c ) ) );
Show( Name Expr( expr ) );
/*:
Name Expr(expr) = sum1(a, sum1(b, c));
I don't like it either.
@XanGregg