[GAP Forum] Correction: How to read loops from 1 file.

Lisette Brillemans lisette.brillemans at mensa.nl
Wed Feb 8 20:48:52 GMT 2012


Gap is a very user friendly program. To read  a file with integers, the only 
thing you need is:


ReadIntegerListsFromFile:=function(file)
local l,f,i,a,r;
  f:=InputTextFile(file);
  a:=[];
  while not IsEndOfStream(f) do
    l:=ReadLine(f);
    if l<>fail then
      l:=Chomp(l); # remove trailing CR/LF
      r:=[];
      for i in SplitString(l," ,") do # separate by SPACE or ,
        if Length(i)>0 then
          Add(r,Int(i));
        fi;
      od;
      Add(a,r);
    fi;
  od;
  CloseStream(f);    # <== New line
  return a;
end;


So easy to remember....

Lisette




More information about the Forum mailing list