On 11/10/2012 07:51 PM, Allin Cottrell wrote:
2) As Sven pointed out, if a function accepts a bundle argument -- in a
context where the content of the bundle is not guaranteed to conform to
a known schema -- the writer may need to determine (a) whether a given
bundle contains an item corresponding to a certain key, and also (b) the
type of the item, if present.
...
OK, so rather than proliferating is*() functions for all types I
suggested a more general typeof() function, which provoked suggestions
and counter-suggestions from Jack and Sven. I'm now not so keen on that
idea. If I'm right that the only serious use case for such testing is in
unpacking bundles [see footnote],
This was just the first thing that I could think of. There may be other
use cases for the is*() functions. For example, say somebody has a
standalone script where at the top he has some global input, and the
script is written to cover all cases. Like:
<top of script>
matrix temp = I(2) # not commented out; active
# scalar temp = 1 # commented out; inactive
</top of script>
And further down in the script only the appropriate parts of the code
are executed:
if ismatrix(temp)
<do matrix stuff>
else
<do scalar stuff>
endif
We may not like that programming style, but should hansl really be
changed to make this impossible, which has worked until now?
And I would bet that still other use cases are out there, because
introspection is a nice feature of a programming language.
[footnote: Jack identified a third case where testing of a variable's
type could be useful, namely in working around bugs relating to the
distinction between scalars and 1x1 matrices. I see that point, but I
don't see it as sufficient reason for a fully general typeof() function
if it's the only use case. When I got to thinking about it, I realized
that implementing a general typeof() -- one that doesn't just accept a
string argument (a putative variable name) -- would actually be quite
tricky.]
Well, AFAICS we have discussed checking variable names, not more. If a
more general coverage is tricky, then maybe keep it simple. To make that
clear the function could be named 'objtype' (for object type) or similar.
thanks,
sven