> < ^ Date: Tue, 24 Jun 1997 15:09:51 +0100
> < ^ From: Steve Linton <sal@dcs.st-and.ac.uk >
^ Subject: Use of PrintTo and AppendTo

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.

For example

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()); 

takes less than 1 second to produce an identical file.

Steve Linton

> < [top]