Skip to content

Native File Replace {R}←X ⎕NREPLACE Y

⎕NREPLACE is used to write data to a native file, replacing data which is already there.

X must be a simple homogeneous APL array containing the data to be written.

Y is a 2- or 3-element integer vector whose elements are as follows:

[1] negative tie number,
[2] start byte, counting from 0, at which the data is to be written; the value ¯1 causes the data to be written from the current position in the file (initially, 0).
[3] conversion code (optional).

See Native File Read for a list of valid conversion codes.

The shy result is the location of the internal file pointer which will be pointing to the end of the newly written data. Used, for example, in:

      ⍝ Replace sequentially from indx.
      { ⎕NREPLACE tie }/vec,indx 

Note that 8 ⎕NINFO ⊃Y can be used to report the current position of the file pointer.

Unicode Edition

Unless you specify the data type in Y[3], a character array will by default be written using type 80.

If the data will not fit into the specified character width (bytes) ⎕NREPLACE will fail with a DOMAIN ERROR.

As a consequence of these two rules, you must specify the data type (either 160 or 320) in order to write Unicode characters whose code-point is in the range 256-65535 and >65535 respectively.

Example

      n'test'⎕NTIE 0 ⍝ See "Example"

      ⎕NREAD n 80 3 0
abc
      ⎕NREAD n 160 7
ταβέρνα

      'εστιατόριο'⎕NREPLACE n 3
DOMAIN ERROR
      'εστιατόριο'⎕NREPLACE n 3
     

      'εστιατόριο'⎕NREPLACE n 3 160
23
      ⎕NREAD n 80 3 0
abc
      ⎕NREAD n 160 10
εστιατόριο

For compatibility with old files, you may specify that the data be converted to type 82 on output. The conversion (to ⎕AV indices) will be determined by the local value of ⎕AVU.