type(5,nonnegint); -> true
type(5,integer); -> true
type(5,posint); -> true
type(5,numeric); -> true
type(5,constant); -> true
?type.
On obtient une explication détaillée avec par exemple
?type,nonnegint.
fact1 := proc(n)
option remember;
if type(n,posint) then
if n=1 then 1 else n*fact1(n-1) fi;
else ERROR(`Wrong type`);
fi;
end;
fact2 := proc(n:posint)
option remember;
if n=1 then 1 else n*fact2(n-1) fi;
end;
type(expr,_type), whattype(expr) et
hastype(expr,_type). whattype() renvoie une
chaîne de caractère qui correspond au type basique auquel
s'identifie l'expression. type(expr,_type) et
hastype(expr,_type) sont des fonctions booléennes qui
permettent de vérifier des types complexes.
g:= 3*x^2 + 2*x - 1; type(g,polynom); -> true whattype(g); -> + type(g,polynom(integer)); -> true
`type/foo`(expr) qui renvoie true ou
false. Malheureusement whattype() n'est pas
redéfinissable.
En fait, on distingue deux familles de types pour les utilisateurs: