[GAP Forum] A strange error
Justin C. Walker
justin at mac.com
Mon Jul 16 19:43:05 BST 2007
Dear Gap Forum and Mathieu,
On Jul 16, 2007, at 08:34 , Mathieu Dutour wrote:
> Dear Gap forum,
> see below a program that creates a strange error.
> ---------------------------------------------
> n:=4;
> for i in [1..n]
> do
> eMat:=4;
> H:=List([1..n], x->x*i*eMat);
> od;
> ---------------------------------------------
> running it with "gap.sh TheProg" produce the following message:
> .
> .
> Syntax error: warning: unbound global variable in BugSearch line 5
> H:=List([1..n], x->x*i*eMat);
> ^
>
> Why is it so?
The manual seems silent on the subject, but after a bit of fiddling,
I will guess that it's a funny sort of scoping problem. Although
scoping seems to be limited to "global" and "local (function)", it
might be that there is block scoping as well. Since you are
introducing 'eMat' within the "scope" of the for loop, perhaps the
variable name 'eMat' does not actually become known until the loop is
(textually) complete.
Certainly, if you assign to 'eMat' prior to typing in the above loop,
it works without a problem.
I'll be interested in the real explanation, since I'm no expert in
the Gap language.
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Enhancement of the Director's Income
--------
Experience is what you get
when you don't get what you want.
--------
More information about the Forum
mailing list