Top
Back: 5.1.137 weight
Forward: 5.2 Control structures
FastBack: 5. Functions and system variables
FastForward: 6. Tricks and pitfalls
Up: 5.1 Functions
Top: Singular 2-0-4 Manual
Contents: Table of Contents
Index: F. Index
About: About This Document

5.1.138 write

Syntax:

write ( link_expression, expression_list )
for DBM links:
write ( link, string_expression, string_expression )
write ( link, string_expression )

Type:

none

Purpose:

writes data to a link.
If the link is of type ASCII, all expressions are converted to strings (and separated by a newline character) before they are written. As a consequence, only such values which can be converted to a string can be written to an ASCII link.
For MP links, ring-dependent expressions are written together with a ring description. To prevent an evaluation of the expression before it is written, the quote command (possibly together with eval) can be used. A write blocks (i.e., does not return to the prompt), as long as a MPtcp link is not ready for writing.
For DBM links, write with three arguments inserts the first string as key and the second string as value into the dbm data base.
Called with two arguments, it deletes the entry with the key specified by the string from the data base.

Example:
 
// write the values of the variables f and i as strings into
// the file "outfile" (overwrite it, if it exists)
write(":w outfile",f,i);

// now append the string "that was f,i" (without the quotes)
// at the end of the file "outfile"
write(":a outfile","that was f,i");
// alternatively, links could be used:
link l=":a outfile"; l;
// type : ASCII
// mode : a
// name : outfile
// open : no
// read : not ready
// write: not ready
write(l," that was f,i");
// saving and retrieving data (ASCII format):
ring r=32003,(x,y,z),dp;
ideal i=x+y,z3+22y;
write(":w save_i",i);// this writes x+y,z3+22y to the file save_i
ring r=32003,(x,y,z),dp;
string s=read("save_i");   //creates the string x+y,z3+22y
execute("ideal k="+s+";"); // this defines an ideal k which
                           // is equal to i.
// for large objects, the MP format and MPfile links are better:
write("MPfile:w save_i.mp",i);
def j=read("MPfile:r save_i.mp");

See Data types; dump; eval; link; print; printf; quote; read; short.


Top Back: 5.1.137 weight Forward: 5.2 Control structures FastBack: 5. Functions and system variables FastForward: 6. Tricks and pitfalls Up: 5.1 Functions Top: Singular 2-0-4 Manual Contents: Table of Contents Index: F. Index About: About This Document
            User manual for Singular version 2-0-4, October 2002, generated by texi2html.