If-else in jmp (e ifmz)So (ora..) che se hai la possibilità di avere un valore mancante e vorresti che fosse valutato come 0 dovresti usare IfMZ in JMP. Quello che mi chiedo cosa sta succedendo nell'esempio seguente, se hai un'istruzione if con "two elses" (non restituirà un errore di sintassi). Nell'esempio seguente è espressione se_espr_tre (e lo stesso per ifmz_expr_three 
Names Default To Here(1);
if_expr_two = Expr(
res = If(val,
Print(Eval Insert("if_expr_two\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("if_expr_two\!t^val^\!tfalse"));
0
);
show(res);
);
// what does this evaluate to and why does val = . return second statement
if_expr_three = Expr(
res = If(val,
Print(Eval Insert("if_expr_three\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("if_expr_three\!t^val^\!tfalse?"));
0;
,
Print(Eval Insert("if_expr_three\!t^val^\!tsomething?"));
-1;
);
show(res);
);
ifmz_expr_two = Expr(
res = IfMZ(val,
Print(Eval Insert("ifmz_expr_two\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("ifmz_expr_two\!t^val^\!tfalse"));
0;
);
show(res);
);
ifmz_expr_three = Expr(
res = IfMZ(val,
Print(Eval Insert("ifmz_expr_three\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("ifmz_expr_three\!t^val^\!tfalse?"));
0;
,
Print(Eval Insert("ifmz_expr_three\!t^val^\!tsomething?"));
-1;
);
show(res);
);
val = 1;
if_expr_two; // OK, prints true and returns 1
if_expr_three; // OK?, prints true and returns 1
ifmz_expr_two; // OK, prints true and returns 1
ifmz_expr_three; // OK?, prints true and returns 1
Write("\!N");
val = 0;
if_expr_two; // OK, prints false and returns 0
if_expr_three; // ? prints false?, but returns missing
ifmz_expr_two; // OK, prints false and returns 0
ifmz_expr_three; // ? prints false?, but returns missing
Write("\!N");
val = .;
if_expr_two; // OK, no print but returns missing value
if_expr_three; // ? prints false? and returns missing
ifmz_expr_two; // OK, prints false and returns 0
ifmz_expr_three; // ? prints false? and returns missing
Write();
Molto probabilmente invierò domande al riguardo al supporto JMP, ma voglio anche chiedere opinioni nella comunità JMP.
Questo è un caso un po' simile a Array associativi e rimozione di chiavi con valore uguale al valore predefinito in tal senso che non sono sicuro del motivo per cui ciò sta accadendo (ho inviato un messaggio al riguardo al supporto jmp, ancora in attesa della risposta finale).
SceneggiaturaRe: If-else in jmp (e ifmz)Dall'indice di script per la funzione If() ( enfasi mia):
Valuta il primo di ogni coppia di argomenti e restituisce la valutazione dell'espressione di risultato associata al primo argomento di condizione che restituisce un risultato diverso da zero. Gli argomenti della condizione vengono valutati in ordine. Se tutti gli argomenti della condizione restituiscono zero, viene valutato l'elemento opzionale elseResult e viene restituito il risultato. Se no elseResult is spec Se ied e nessuna delle condizioni è vera, viene restituito un valore mancante. Se tutti gli argomenti della condizione risultano mancanti, viene restituito un valore mancante.
Ho messo in grassetto la parte di importazione, "Valuta il primo di ogni coppia..."
Quindi, un If() con tre virgole ha due coppie. Considera questo:
a=3;
If(
a==1, show("a==1"), //first pair - evaluate whether a==1
a==2, show("a==3") //second pair - evaluate whether a==2
);
Che If() restituirà mancante perché non c'era un'espressione "first of each pair" che restituisse un valore diverso da zero.
Nella tua funzione If():
If(
val,Print(Eval Insert("if_expr_three\!t^val^\!ttrue")); 1;, // first pair - evaluate whether val is nonZero
//begin second pair
Print(Eval Insert("if_expr_three\!t^val^\!tfalse?"));0; ,
Print(Eval Insert("if_expr_three\!t^val^\!tsomething?"));-1;
// second pair -- evaluate Print(); 0; - that returns 0 (since that was the last value in the expression) - so the second condition isn't nozero
);
Ricorda che JSL è un linguaggio puramente funzionale con operatori per facilitarne la lettura ma il ; è l'operatore per il Funzione Colla() . La funzione Glue() restituisce l'ultima espressione valutata.
Vedere: La differenza tra colla e se