[GAP Forum] Syntax error
Sven Reichard
sven.reichard at tu-dresden.de
Fri Jan 26 12:00:11 GMT 2018
Dear Angel,
I ran your code and could not reproduce that specific error. Which
program did you use to create the input file? Is there anything above
the function declaration in that file? Possibly a statement without a
closing semicolon?
However, you should declare as local the variables you introduce within
the function, by adding
local primos, i;
as the second line of your file. Otherwise your function will overwrite
any possible global variables of these names. If you want to use the
list afterwards, you can add a return statement
return primos;
just before the "end" statement.
Another way to obtain the information you are interested in is
primos := Filtered([1..n], IsPrime);
Hope this helps
Regards,
Sven Reichard.
Institut für Algebra
TU Dresden
On 26.01.2018 12:24, Angel Blasco wrote:
> 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
>
More information about the Forum
mailing list