是什麼激發了這個願望清單請求?
JMP 有多種不同的方式來指示值是否為空、缺失或 null,並且函數/操作在沒有值時與有值時可能會返回不同的類型(在 Python 中,“pythonic”方式只是檢查值在If語句中,因為物件將為false內建類型/真值測試)。
您希望看到什麼改進?
更通用的 JSL 函數來檢查值是否為空/缺失/null/沒有值。 以下是該函數的一個範例(希望其他人有更多的想法):
Names Default To Here(1);
Is None = function({obj, keep_zero = 1}, {Default Local},
/*"""Attempt to check if object is None (Empty(), ., 0, "", {}, [], [=>], [](0,1)...
Args:
obj: object to check
Returns:
int: 0 if non-zero and 1 if zero
Examples:
>> show(Is None([1 => 2]));
Is None([1 => 2]) = 0;
>> show(Is None(Associative Array()));
Is None(Associative Array()) = 1;
"""*/
cur_type = Type(obj);
return(
If(Contains({"List", "Matrix", "Associative Array"}, cur_type), // check items in list, matrix and associative array
!N Items(obj);
, cur_type == "String",
!Length(obj); // check string length, Is Missing() should also work
, Contains({"Integer", "Number"}, cur_type),
If(IsMissing(obj),
1
, keep_zero & obj == 0,
1
,
0
);
, cur_type == "Empty",
1;
,
0;
);
);
);
Print("Zeros:");
show(Is None([1 => 2]));
show(Is None({"a"}));
show(Is None([1]));
show(Is None(1));
show(Is None("a"));
Write("\!N");
Print("Ones:");
show(Is None(Associative Array()));
show(Is None({}));
show(Is None([]));
show(Is None(0));
show(Is None(""));
show(Is None(.));
show(Is None(Empty()));
為什麼這個想法很重要?
可以更輕鬆地建立比較,而無需猜測這次應該實現哪個檢查(IsMissing()、Is Empty()、N Items() > 0、Zero Or Missing()...)