putfile←{                               ⍝ Put rows to text-file.
    ⍺←2 ⋄ term(-⍺)↑⎕UCS 13 10          ⍝ default: cr-lf terminated rows.
    fid rows←⍵                          ⍝ file-id and row values.
    1=≡,rows:⍺ ∇ fid(rows)             ⍝ single row: enclose.
    ntie←{                              ⍝ handle on null file.
        0::⎕SIGNAL ⎕EN                  ⍝ signal error to caller.
        22::⍵ ⎕NCREATE 0                ⍝ ~exists: create.
        0 ⎕NRESIZE ⍵ ⎕NTIE 0            ⍝  exists: truncate.
    }fid
    cvec←↑,/rows,¨⊂term                 ⍝ collected, terminated lines.
    sizecvec ⎕NAPPEND ntie,⎕DR ⎕AV     ⍝ write lines to file.
    1:rsltsize⊣⎕NUNTIE ntie            ⍝ shy result: file size.
}

code_colours

test script

Back to: notes

Back to: Workspaces