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 "due altri" (non restituirà un errore di sintassi). Nell'esempio seguente è espressione if_expr_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 all'assistenza di JMP, ma voglio anche chiedere opinioni nella comunità di JMP.
Questo è un caso un po' simile a Array associativi e rimozione di chiavi con valore uguale al valore predefinito in tal senso non sono sicuro del motivo per cui sta accadendo (ho inviato un messaggio a riguardo al supporto jmp, ancora in attesa della risposta finale).
Automazione e scriptingRi: If-else in jmp (e ifmz)Dall'indice di scripting per la funzione If() ( sottolineatura mia):
Valuta il primo di ogni coppia di argomenti e restituisce la valutazione dell'espressione del risultato associata al primo argomento della 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'opzionale elseResult e viene restituito il risultato. Se no elseIl risultato è 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
);
Quel If() restituirà missing 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 Funzione colla() . La funzione Glue() restituisce l'ultima espressione valutata.
Vedere: La differenza tra colla e se