cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-612938%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EAjouter%20une%20fonction%20qui%20peut%20%C3%AAtre%20universellement%20utilis%C3%A9e%20pour%20v%C3%A9rifier%20si%20l'objet%2Fla%20variable%20est%20vide%2Fmanquant%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-612938%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSTRONG%3EQu'est-ce%20qui%20a%20inspir%C3%A9%20cette%20demande%20de%20liste%20de%20souhaits%26nbsp%3B%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EJMP%20dispose%20de%20plusieurs%20mani%C3%A8res%20diff%C3%A9rentes%20d'indiquer%20si%20les%20valeurs%20sont%20vides%2C%20manquantes%20ou%20nulles%20et%20les%20fonctions%2Fop%C3%A9rations%20peuvent%20renvoyer%20diff%C3%A9rents%20types%20lorsqu'elles%20n'ont%20pas%20de%20valeur%20par%20rapport%20%C3%A0%20lorsqu'elles%20en%20ont%20(et%20en%20Python%2C%20la%20m%C3%A9thode%20%22pythonique%22%20serait%20simplement%20de%20v%C3%A9rifier%20la%20valeur%20dans%20l'instruction%20If%20car%20les%20objets%20seront%20faux%20%3CA%20href%3D%22https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fstdtypes.html%23truth-value-testing%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E(Types%20int%C3%A9gr%C3%A9s%2FTest%20de%20valeur%20de%20v%C3%A9rit%C3%A9%3C%2FA%3E%20).%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQuelle%20est%20l%E2%80%99am%C3%A9lioration%20que%20vous%20souhaiteriez%20voir%20%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFonction%20JSL%20plus%20universelle%20pour%20v%C3%A9rifier%20si%20la%20valeur%20est%20vide%2Fmanquante%2Fnulle%2Fn'a%20aucune%20valeur.%20Vous%20trouverez%20ci-dessous%20un%20exemple%20de%20fonction%20(j'esp%C3%A8re%20que%20d'autres%20auront%20des%20id%C3%A9es%20suppl%C3%A9mentaires)%26nbsp%3B%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0AIs%20None%20%3D%20function(%7Bobj%2C%20keep_zero%20%3D%201%7D%2C%20%7BDefault%20Local%7D%2C%0A%09%2F*%22%22%22Attempt%20to%20check%20if%20object%20is%20None%20(Empty()%2C%20.%2C%200%2C%20%22%22%2C%20%7B%7D%2C%20%5B%5D%2C%20%5B%3D%26gt%3B%5D%2C%20%5B%5D(0%2C1)...%0A%09%0A%09Args%3A%0A%09%09obj%3A%20object%20to%20check%0A%09%0A%09Returns%3A%0A%09%09int%3A%200%20if%20non-zero%20and%201%20if%20zero%0A%09%09%0A%09Examples%3A%0A%09%09%26gt%3B%26gt%3B%20show(Is%20None(%5B1%20%3D%26gt%3B%202%5D))%3B%0A%09%09%09Is%20None(%5B1%20%3D%26gt%3B%202%5D)%20%3D%200%3B%0A%09%09%26gt%3B%26gt%3B%20show(Is%20None(Associative%20Array()))%3B%0A%09%09%09Is%20None(Associative%20Array())%20%3D%201%3B%0A%09%22%22%22*%2F%0A%09cur_type%20%3D%20Type(obj)%3B%0A%09return(%0A%09%09If(Contains(%7B%22List%22%2C%20%22Matrix%22%2C%20%22Associative%20Array%22%7D%2C%20cur_type)%2C%20%2F%2F%20check%20items%20in%20list%2C%20matrix%20and%20associative%20array%0A%09%09%09!N%20Items(obj)%3B%0A%09%09%2C%20cur_type%20%3D%3D%20%22String%22%2C%20%0A%09%09%09!Length(obj)%3B%20%2F%2F%20check%20string%20length%2C%20Is%20Missing()%20should%20also%20work%0A%09%09%2C%20Contains(%7B%22Integer%22%2C%20%22Number%22%7D%2C%20cur_type)%2C%0A%09%09%09If(IsMissing(obj)%2C%0A%09%09%09%091%0A%09%09%09%2C%20keep_zero%20%26amp%3B%20obj%20%3D%3D%200%2C%0A%09%09%09%091%0A%09%09%09%2C%0A%09%09%09%090%0A%09%09%09)%3B%0A%09%09%2C%20cur_type%20%3D%3D%20%22Empty%22%2C%0A%09%09%091%3B%0A%09%09%2C%0A%09%09%090%3B%0A%09%09)%3B%0A%09)%3B%09%0A)%3B%0A%0A%0APrint(%22Zeros%3A%22)%3B%0Ashow(Is%20None(%5B1%20%3D%26gt%3B%202%5D))%3B%0Ashow(Is%20None(%7B%22a%22%7D))%3B%0Ashow(Is%20None(%5B1%5D))%3B%0Ashow(Is%20None(1))%3B%20%0Ashow(Is%20None(%22a%22))%3B%0AWrite(%22%5C!N%22)%3B%0APrint(%22Ones%3A%22)%3B%0Ashow(Is%20None(Associative%20Array()))%3B%0Ashow(Is%20None(%7B%7D))%3B%0Ashow(Is%20None(%5B%5D))%3B%0Ashow(Is%20None(0))%3B%0Ashow(Is%20None(%22%22))%3B%0Ashow(Is%20None(.))%3B%0Ashow(Is%20None(Empty()))%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPourquoi%20cette%20id%C3%A9e%20est-elle%20importante%20%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFacilite%20la%20cr%C3%A9ation%20de%20comparaisons%20sans%20deviner%20quelle%20v%C3%A9rification%20doit%20%C3%AAtre%20impl%C3%A9ment%C3%A9e%20cette%20fois-ci%20(IsMissing()%2C%20Is%20Empty()%2C%20N%20Items()%20%26gt%3B%200%2C%20Zero%20Or%20Missing()...)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-612938%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAutomatisation%20et%20scripts%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-742400%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%20%3A%20Ajouter%20une%20fonction%20qui%20peut%20%C3%AAtre%20utilis%C3%A9e%20universellement%20pour%20v%C3%A9rifier%20si%20un%20objet%2Fune%20variable%20est%20vide%2Fmanquant%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-742400%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2Fdt-image-missing%2Fm-p%2F742373%23M92238%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2Fdt-image-missing%2Fmp%2F742373%23M92238%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar

Add function which can be universally used to check if object/variable is empty/missing

What inspired this wish list request? 

JMP has multiple different ways to indicate if values are empty, missing or null and functions/operations might return different types when they have no values when compared to when they do have (and in Python the "pythonic" way would be just to check value in If-statement as the objects will be false Built-in Types/Truth Value Testing).

 

What is the improvement you would like to see?

More universal JSL function to check if value is empty/missing/null/has no value. Below is one example for the function (hopefully others have additional ideas):

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()));

 

Why is this idea important?

Makes it easier to build comparisons without guessing which check should be implemented this time (IsMissing(), Is Empty(), N Items() > 0, Zero Or Missing()...)

1 Comment
Craige_Hales
Super User