Type::Singleton
-- type to
identify exactly one objecttesttype(x,
Type::Singleton(y)) is equivalent to
bool(x = y)
.
testtype(obj,
Type::Singleton(t_obj)
)
obj |
- | any MuPAD object |
t_obj |
- | any object to identify |
see testtype
_equal
, bool
, testtype
, Type::Union
testtype(obj,
Type::Singleton(t_obj
)
) is equivalent to
bool(x = y)
, but the latter is faster.Type::Singleton
can be used to create combined types,
especially in conjunction with Type::Union
, Type::Equation
and other types
expecting type information for subexpressions (see example 2).Check, if x
is really x
:
>> testtype(x, Type::Singleton(x))
TRUE
But the next call does the same:
>> bool(x = x)
TRUE
Type::Singleton
exists to create special
testing expressions:
>> T := Type::Union(Type::Singleton(hold(All)), Type::Constant):
With the type T
the option All
and any constant can be identified with one call of testtype:
>> testtype(4, T), testtype(hold(All), T), testtype(x, T)
TRUE, TRUE, FALSE
But (e.g., in procedures) the following example works faster:
>> test := X -> testtype(X, Type::Constant) or bool(X = hold(All)): test(4), test(hold(All)), test(x)
TRUE, TRUE, FALSE
One way to test a list of options for syntactical correctness is the following:
>> T := Type::Union( // Name = "..." Type::Equation(Type::Singleton(hold(Name)), DOM_STRING), // Mode = n, n in {1, 2, 3} Type::Equation(Type::Singleton(hold(Mode)), Type::Interval([1,3], Type::Integer)), // Quiet Type::Singleton(hold(Quiet)) ):
>> testtype((Name = "abcde", Quiet), Type::SequenceOf(T))
TRUE
We only allow the values 1, 2, and
3 for Mode
, however:
>> testtype((Quiet, Mode = 0), Type::SequenceOf(T))
FALSE
Obviously, it would be a good idea to tell the user which options we could not grok:
>> error("Unknown option(s): ".expr2text( select((Quiet, Mode = 0), not testtype, Type::SequenceOf(T))))
Error: Unknown option(s): Mode = 0
>> delete T, test: