Dyalog Primer - Files - Native Files
⍝ Download the file <doggerel.txt> and save it locally
'c:\dick\temp\doggerel.txt' ⎕ntie ¯1
dog←⎕nread ¯1 82 (⎕nsize ¯1)
dogmat←dogmat,⊃31↑¨'That''s a pile of tripe' 'I''ll remember it
tie←'c:\dick\temp\newdog.txt' ⎕NCREATE 0
of the syntax here has its roots in pre-history.
files are strings of bytes.
- Terminal control
characters visually split them into lines or records.
makes sense for APL to read as much of a file into the workspace as
- It's often a matter of taste
whether to handle native character data as a matrix or as a vector of
vectors (often the application will "suggest" the appropriate design).
writing back to a native file, remember to add the newline characters
and make a simple vector.
- You can use explicit tie
numbers, or let APL set the number automatically.
handled in the current example - native files that contain numeric
representations (such as floating point values).
- Native File System Functions (Dyalog Language Reference)
⎕NAPPEND ⎕NCREATE ⎕NERASE ⎕NLOCK
⎕NNAMES ⎕NNUMS ⎕NREAD ⎕NRENAME ⎕NREPLACE ⎕NRESIZE ⎕NSIZE ⎕NTIE ⎕NUNTIE
- Associated System Functions (Dyalog Language Reference)
- Mapped Files System Functions (Dyalog Language Reference)
- Define a function which reads a (character) native file and
returns its entire content as a matrix (CR/LF pairs in the file
indicate row endings).
- Define a function which takes a character matrix and writes
its content to a new native file (rows in the input matrix should be
separated in the file by CR/LF pairs).
- Define a function which appends its (character vector)
right argument to the native filed named in its left argument - its
result should be the size of the native file after the append.
- Define a function which takes a string of integers and
writes them to a new native file, each integer represented as an 8-bit
- Define a function which takes a simple homogeneous APL
array as its argument and creates a new native file from which the
array can be recreated. The file has to contain
- The rank of the array (write this as an 8-bit signed
- The shape of the array (write this as a succession of
8-bit signed integers)
- The ravel of the array value (write this as 8-bit
characters if it is a character array, 64-bit floating if it is a