> < ^ Date: Mon, 02 Nov 1992 10:53:35 +0100
> < ^ From: Eamonn O'Brien <obrien@math.auckland.ac.nz >
> ^ Subject: Reading from files

Why does the following piece of code not work? It generates
an error message

Error, Variable 'G' must have a value at
...

I know that by not declaring G locally within the procedure
I can persuade it to work OK -- but if I do that, it
overwrites whatever existing value G had.

This may have serious side effects -- where for example
I have a group G defined in Gap, and I now want to read
another group called G defined in "file.g" and return it
from ReadFromFile to the main level
under some other name. Is there any sensible way to
achieve this without wiping out my existing G?

I guess that I can encase the definition of G in the file
within a function and call that function. But are there
other approaches? Is this problem something which is
intended /unavoidable / or a bug?

Thanks,
Eamonn O'Brien
obrien@pell.anu.edu.au

##################################################
#code to read value from file and return it
ReadFromFile := function ()

local exist, G;

   exist := READ("file.g");
   return G;
end; #ReadFromFile

l := ReadFromFile ();
Print ("The value returned from the function is ", l, "\n");

############################################################

#contents of file.g
G := 5;

> < [top]