On Tue, 25 Nov 2014, Logan Kelly wrote:
I need a function the tests if variable is in an array (sorry for
the poor wording of this sentence). What I mean by this is a
function that compares each element of an array to a variable and
returns 0 if no elements of the array are equal and the position
in the array of the first instance of equality. So here are my
question:
1. Dose such a function exist? (I haven't found one, but I
thought I should ask)
No.
2. If not, coding it up is no problem, but I need a way to check
the data type of variable. Is there such a command?
Well, there's actually a "hidden" function typeof(), which returns
the same code numbers as inbundle(). I started documenting it after
reading your posting but on second thoughts I'm not sure we really
want to do that in its present state. Returning a "magic" integer
code is not very nice at all: if we need such a function we'd be
better off defining symbolic constants SCALAR, SERIES, MATRIX and so
on. Then you could do
if typeof(foo) == SERIES
...
endif
where you'd now have to do
if typestr(typeof(foo)) == "series"
...
endif
Documenting the latter would be giving a hostage to backward
compatibility. Moreover, I'm not sure that going very far in this
direction ("introspection") is something we want to do with hansl,
though I'm open to discussion of the point.
3. Is there a way, other than using a bundle, to pass a variable
of unknown data type to a function?
No. All arguments to user-defined functions must be of a definite,
specified type (though they may be optional).
More generally, could you give us an idea of why you need this sort
of thing? I suspect there may be another way of doing whatever it is
you're trying to do.
Allin