Dear GAP forum,
In responding to a user query I came across a feature of GAP (version
3) which is not as well known as it should be.
When evaluating <expression> in PrintTo( <file>, <expression> )
anything printed with Print will be written to <file>, rather than
to the screen. AppendTo behaves likewise.
Furthermore, <file> will be opened once at the start of evaluation and
closed at the end. Repeated calls to AppendTo involve opening and
closing it for each call and so take much more real time.
gap> for i in [1..1000] do > AppendTo("foo", i^3); > od;
takes about 25 real-time seconds, whereas:
gap> bar := function() > for i in [1..1000] do > Print(i^3); > od; end; function ( ) ... end gap> PrintTo("foo1",bar()); gap>
takes less than 1 second to produce an identical file.