kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Update \: to include 6: #530

Closed tavmem closed 5 years ago

tavmem commented 5 years ago

Richard H wrote:

Is there any (simple and efficient) way to append to a plain text file (e.g: a diagnostic log).
I have been playing with the 0:, 1: etc. I/O verbs but these seem to deal with entire text 
files in one operation.
The only way I can come up with so far is to read the entire file into memory, append 
the new text and then write the entire file back to disk. Although that works it can hardly 
be 'efficient' for large files.
Is there any equivalent to bash >> or linux O_APPEND?
Thanks, Richard.

Bakul responded:

(,”foo”)6:”bar\n”Will append bar to file foo
I think this was documented is some later release notes. Can’t recall.
You can file bug report to get the help you get with \: updated
tavmem commented 5 years ago

Actually, it looks like this documentation is already in Kona. It is just not in the k2 manuals.

  \:
I/O Verbs 0: 1: 2: 3: 4: 5: 6:

Disk
0: dyadic   write text file `f 0: "hello" 
0: monadic  read text file  0: `f
1: dyadic   write binary file `f 1: 4 5 6 
1: monadic  read binary file  1: `f (mmapped)
2: monadic  read binary file  2: `f (copied to memory)
3: dyadic   append to binary file, w/o sync `f 3: ,7
5: dyadic   append to binary file `f 5: ,7
6: dyadic   write raw byte string `f 6: "\01\02\03"
6: monadic  read raw byte string  6: `f