On Wed, 12 Mar 2003, Greg Gamble wrote:
On Wed, Mar 12, 2003 at 10:31:56AM -0500, Vahid Dabbaghianabdoly wrote:
> Dear Gap-Froum,
> I have written a recursive program on GAP which contains two
> subroutines A and B such that A calls B, and B calls A.
> When I define A at the first, GAP does not know B.
> and when I define B, it does not know A. And I receive
> "Syntax error: warning: unbound global variable".
> Do you know How I can fix that?
Interactively, you can safely ignore it ... it is just a warning.
However to define two functions f and g that call each other in
such a way that avoids the warning use DeclareGlobalFunction and
InstallGlobalFunction to define each function like this:
DeclareGlobalFunction( "f" );
DeclareGlobalFunction( "g" );
# code here can refer to g
# code here can refer to f
The problem with that approach occurs when you incrementally develop and
debug you code, since Install... makes f and g read-only variables. If I
remember correctly, if you make changes to your code, you need to restart
Another work-around that I have employed is the following:
A := fail; # or any other value B := function() # uses A end; A := function() # uses B end;
This avoids the warning, and still lets you overwrite A and B. In
production code, you might want to replace this by Greg's code.
Dept. of Math. Sci.
University of Delaware