[GAP Forum] Syntax error
Kieran Roberts
kroberts at math.uni-bielefeld.de
Fri Jan 26 12:26:28 GMT 2018
You need to declare any local variables at the very top of your
function. (See https://www.gap-system.org/Manuals/doc/tut/chap4.html#X797E24D67BB804A2).
In your case, your function would need to be rewritten as:
ListaPrimos:=function(n)
local primos, i;
primos:=[];
for i in [1..n] do
if IsPrime(i) then
Add(primos,i);
fi;
od;
PrintTo("C:/primos.log",primos);
Print(primos);
Print(" Se han encontrado ",Length(primos)," primos entre 1 y ",n);
end;
> Message: 2
> Date: Fri, 26 Jan 2018 12:24:33 +0100
> From: Angel Blasco <angelblascomunoz at gmail.com>
> To: forum at gap-system.org
> Subject: [GAP Forum] Syntax error
> Message-ID:
> <CABuTqFap=E-Zt=BJtx73MefRpyRDWbfoJ1iCzfHQ-HncnKx7fA at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Dear forum, I'm a newbie user of GAP so this question maybe looks very
> simple. I've written a function and saved it into a text file called
> "ListaPrimos.g". I've tried to read it from GAP using Read command, and
> this is the output message:
>
>
> gap> Read("C:/gapListaPrimos/ListaPrimos.g");
> Syntax error: expression expected in C:/gapListaPrimos/ListaPrimos.g line 1
> ?ListaPrimos:=function(n)
> ^
>
>
>
> The function is:
>
> ListaPrimos:=function(n)
> primos:=[];
> for i in [1..n] do
> if IsPrime(i) then
> Add(primos,i);
> fi;
> od;
> PrintTo("C:/primos.log",primos);
> Print(primos);
> Print(" Se han encontrado ",Length(primos)," primos entre 1 y ",n);
> end;
>
> What is the expression expected?
>
> Regards
> --
> *Angel Blasco.*
More information about the Forum
mailing list