Bill Allombert on Mon, 01 Sep 2008 22:47:09 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Readline


On Mon, Sep 01, 2008 at 09:21:39PM +0200, Martin Larsen wrote:
> 
> 
> So, local variables are seen by all functions in the same scriptfile,
> but should not be seen outside.

Scriptfile are not relevant.
A variable declared with local() inside the function foo() is visible by all
other functions until foo() terminate. It is dynamically scoped.

> >> But this variable is not removed from global function (sic) namespace.
> >>
> >> Here is what happens:
> >>
> >>>myvar(n)= n*n
> >> *** unused characters: myvar(n)=n*n
> >
> > This was a limitation of GP 2.3 which was fixed in GP 2.4. In GP 2.4,
> > you can replace function with variable and vice-versa.
> >
> 
> I see a related problem now:
> 
> Lets say you have loaded a script with local(myvar).
> 
> If you create (perhaps unknowingly) a global variable with the same
> name and then kill(myvar) then you destroy all myvar's and the use of
> the function it was declared in (version 2.3.4).

The function kill() is very problematic and should be avoided at all
cost.  It kill formal variables:
? for(i=1,2^17,kill(z);z='z)
  ***   no more variables available.
? z
  ***   no more variables available.

In PARI 2.4, you do not need kill to replace a function by a variable,
so it is mostly useless.

Cheers,
Bill.