Allin,
Sorry for the delay in my response. Thanksgiving, family and all that :-)
Generally, I want to create an array of strings form a text file, but I want to check for
duplicates. That is easy enough to do, but I got to thinking it might be nice to have a
function that could work with all array types (so I decided to give it a try). However, I
don't think that it can be done with hansl. A separate function for each data type
would be needed because to make a single function for all types the function would not
know the data types of the arguments ahead of time.
More generally, I am working on a project that can turn a gretl data set into a flat
file.
Thanks,
Logan
-----Original Message-----
From: gretl-devel-bounces(a)lists.wfu.edu [mailto:gretl-devel-
bounces(a)lists.wfu.edu] On Behalf Of Allin Cottrell
Sent: Wednesday, November 26, 2014 3:29 PM
To: Gretl development
Subject: Re: [Gretl-devel] is there an inarray function?
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
_______________________________________________
Gretl-devel mailing list
Gretl-devel(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel