[Gretl-devel] Bug in help file

Allin Cottrell cottrell at wfu.edu
Wed Sep 12 19:37:26 EDT 2007


On Wed, 12 Sep 2007, I wrote:

> On Wed, 12 Sep 2007, Riccardo (Jack) Lucchetti wrote:
> > "Gamma" is a rather special case. Of all Greek letters, it's the 
> > only one that's more likely to be used to indicate a function 
> > than a parameter...
> 
> Actually, I just took a look and I think that genr is smart 
> enough not to confuse variables with functions, without the 
> prohibition on using function names for variables...

But let's think about this some more.  In a language such as C, 
it's not possible for user-defined variables and built-in 
functions to share the same name -- because functions _are_ 
variables (you can pass functions as arguments to other functions, 
assign functions as members of structures, and so on).

In C, you're free to define a variable called, for example, 
"printf", as in

 double printf = 2.56;

But if you do so, you've lost the well-known standard C library 
function printf; that variable is over-written.

How does this relate to gretl?  Well, right now there's no _real_ 
collision between a variable called "gamma" and the gretl genr 
function gamma, because functions are _not_ treated as variables 
in gretl scripting.  There's no collision, because when "gamma" 
serves as the name of a function it must always be in the context 
of a function call, where the string "gamma" is immediately 
followed by a left parenthesis.  (And left parenthesis immediately 
following a variable name is a gretl syntax error.)

On the one hand, this means that we're quite secure in relaxing 
the prohibition on user-defined variables with the same name as 
gretl functions.  Gretl can cope just fine with

  genr gamma = gamma(1.5)

On the other hand, we should think twice about being permissive if 
we reckon we might wish to expand gretl syntax in a C-like 
direction in future.  If we might want to treat functions as 
variables, we probably shouldn't be permissive.

Unless, that is, we want to be as hard-nosed as C itself, and say 
that if you want to over-write the gamma function with a variable 
named gamma that's your prerogative, but then you've lost the 
gamma function.

IMO it's not very likely that we'd want to treat gretl functions 
as variables, but any other thoughts?

Allin.


More information about the Gretl-devel mailing list