File << Thing -- print to a file

Synopsis

• Operator: <<
• Usage:
f << x
<< x
• Inputs:
• Outputs:
• a file, the output file(s) used
• Consequences:
• The object x is prepared for printing (with net) and printed on the output file(s) f. If f is a string, then it is interpreted as a filename and an output file is opened, used, and returned, unless a single open file with the same name already exists, in which case it is used and returned. Filenames starting with ! or with \$ are treated specially, see openInOut. If f is a list, then the output operation is performed on each one. If f is null, then the output is discarded; thus null is useful as a dummy output file. If f is omitted, as in the second usage line, then the output is sent to stdio, and it will appear (usually) on the screen.

Description

Parsing of << associates leftward, so that several objects may be displayed with an expression such as f<<x<<y<<z.

 i1 : stderr << "-- hi there --" << endl -- hi there -- o1 = stderr o1 : File i2 : << "-- ho there --" << endl -- ho there -- o2 = stdio o2 : File i3 : fn = temporaryFileName() o3 = /tmp/M2-63129-0/0 i4 : fn << "hi there" << endl << close o4 = /tmp/M2-63129-0/0 o4 : File i5 : get fn o5 = hi there i6 : R = QQ[x] o6 = R o6 : PolynomialRing i7 : f = (x+1)^10 10 9 8 7 6 5 4 3 2 o7 = x + 10x + 45x + 120x + 210x + 252x + 210x + 120x + 45x + 10x + ------------------------------------------------------------------------ 1 o7 : R i8 : << f 10 9 8 7 6 5 4 3 2 x + 10x + 45x + 120x + 210x + 252x + 210x + 120x + 45x + 10x + 1 o8 = stdio o8 : File i9 : fn << f << close o9 = /tmp/M2-63129-0/0 o9 : File i10 : get fn o10 = 10 9 8 7 6 5 4 3 2 x + 10x + 45x + 120x + 210x + 252x + 210x + 120x + 45x + 10x + 1 i11 : fn << toExternalString f << close o11 = /tmp/M2-63129-0/0 o11 : File i12 : get fn o12 = x^10+10*x^9+45*x^8+120*x^7+210*x^6+252*x^5+210*x^4+120*x^3+45*x^2+10*x+ 1 i13 : value get fn 10 9 8 7 6 5 4 3 2 o13 = x + 10x + 45x + 120x + 210x + 252x + 210x + 120x + 45x + 10x ----------------------------------------------------------------------- + 1 o13 : R i14 : removeFile fn