Ilya Zakharevich on Tue, 25 Feb 2003 14:01:39 -0800


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

Re: gp: variables


On Tue, Feb 25, 2003 at 11:50:25AM +0100, Karim BELABAS wrote:
> > Seems like a bug to me.

> Calling a function as f(x, x = y) is syntactically correct, but should not be
> used [ this is implicitly what you do, through side effects of subroutines ].

> Basically, it depends on the order in which the arguments are evaluated.
> The result is undefined [ actually you could get a SEGV here ].

Well, thinking of side-effects of subroutines given as arguments to
other subroutines is too much to require from users.  Something better
be changed.

> There _is_ a bug in PARI here, in that variables may have too short a
> lifespan: variables values are passed as reference to a cloned "durable"
> object, not as copies.

"Passed" by who?  The interpreter of '=' and of the function calls?

> If this object is affected, so are the values. This
> is OK in x = y, since the assignment makes a copy of the y-value into x,
				      ^
				       immediately

> but it definitely is not in function arguments.
 
> And anyway the possibility of SEGV is annoying...
> 
> I do not know how to correct this without a major slowdown [ always make full
> copies, whenever referencing a variable value ]. Adding reference counts
> wouldn't help, since objects components are modified, without the parent
> object being able to tell about it.

So the reference count should be on components.

Actually, Perl has a similar problem: it has reference counts, but for
speed they are not updated for function arguments.  Due to much
tighter binding of "values" to "variables" (comparing to PARI) it is
much harder to trigger this bug.  But once in several years I'm bit by
it (and it is always a long time to debug)...

Ilya