On 11/09/2012 07:30 PM, Allin Cottrell wrote:
On Fri, 9 Nov 2012, Riccardo (Jack) Lucchetti wrote:
> On Fri, 9 Nov 2012, Allin Cottrell wrote:
>
>>
>> if typeof(whatever) != "scalar"
>> ...
>> endif
>
> I like this.
I do, too, but why not just use the word 'type'. The "of" part is
already indicated by the parentheses, no?
...
> The only think I'd change from Allin's proposal is to
introduce an
> integer-based coding system, such as 1=scalar, 2=series etc and have typeof()
> return a scalar. For performance reasons, the less we use strings, the
> better.
Good point.
I beg to disagree, I would favor explicitness and readability of the
code over some marginal performance gain. It would be a major (well ok,
maybe not major, but still) step backwards from being able to use 'if
islist()', which is self-explanatory, towards 'if type()==3' which is
totally mysterious. But 'if type()=="list"' would be on par with the
current status IMO.
I've sometimes wondered if it would be worth trying to expose
some sort of "enum" system in gretl -- e.g. in this context
NONE = 0, SCALAR = 1, SERIES = 2 and so on. It would obviously
be more intuitive to be able to do
if typeof(whatever) == SCALAR
This would be ok, too, IMO.
where SCALAR codes for an integer. But it means "invading" the
user's available namespace, plus more internal string look-up,
so maybe it's not worth the trouble outside of a compiled
language.
As I said, I'm strongly in favor of using strings or pseudo-strings
(global constants) here. Also, the words "series", "scalar" etc. are
already reserved words, so I don't see any additional invasion.
thanks,
sven