Am 21.04.2020 um 21:06 schrieb Artur Tarassow:
Am 20.04.20 um 12:28 schrieb Sven Schreiber:
> Am 19.04.20 um 17:06 schrieb Allin Cottrell:
>> Now talking of typeof(): it returns numeric type codes,
which
>> typestr() can "translate". Not all that convenient. We recently
>> introduced the symbolic constants TRUE and FALSE. Would it be overkill
>> to introduce a few more: NULL, SCALAR, SERIES, MATRIX, STRING, BUNDLE,
>> ARRAY? In that case you could do things like
>>
>> if typeof(b.m) == MATRIX
>>
> Spontaneously I'm not sure if that's necessary. OTOH if something like
> that is done I think it should go all the way and also differentiate
> different types of arrays. Maybe typeof() could just accept an optional
> second string literal argument which then triggers such an equality
> check:
>
> if typeof(b.m, "matrix") # returns 1 if b.m is a matrix
...
However, I don't think it's clean to "augment" the
typeof() function in
Sven's proposed way. Returning the type of some 'object' and checking
whether some 'object' is of a specified type are two different issues.
And I think it's much cleaner to have two separate functions for two
different issues.
Reviving this thread and these ideas: Point taken by Artur, OK.
The most important gap IMO is the missing differentiation between
different array types (matrices, strings, etc.). And using the first
array element of an array wouldn't work in the case of an empty array.
(As in 'matrices M = array(0)'.)
So here's another idea: Extend the typeof() function to spit out new
codes for matrices, strings, lists, bundles (and "arrays" I guess?)
instead of just 6 which stands for array. For example 10 + the
individual code for the object:
- 13 for matrices
- 14 for strings
- 15 for bundles
- 16 for arrays
- 17 for lists
An optional argument could be introduced for that such that:
- typeof(M) gives 6
- typeof(M, TRUE) gives 13
And then typestr() would have to understand these new codes, of course.
Personally I think having to type typestr(typeof( ...)) isn't so bad,
although of course there's also room for improvement.
cheers
sven