Re: Beginner's question: open and close file

2019-03-12 Thread Hongwei Xi
You can use a stream of chars for the content of a given file. Or use a stream of blocks of chars for the content of a given file, where each block is of size, say, 4096 bytes. For the start, using a stream of chars is a good choice. Please stay away from the urge to write "efficient" code at this

Re: Beginner's question: open and close file

2019-03-12 Thread Shimin Guo
On Tue, Mar 12, 2019 at 12:23 PM Hongwei Xi wrote: > Here is a quick fix: > extern > praxi > clear{a:t0ype}(x: INV(a)): void > > fun open_close(): void = > let > val fptr = fopen("hello.dats", file_mode_r) > val p = ptrcast(fptr) > in > if p = 0 > then > let > prval () =

Re: Beginner's question: open and close file

2019-03-12 Thread Shimin Guo
Cool. I was looking in http://ats-lang.github.io/DOCUMENT/ATS-Postiats/libats/libc/HTML/ATSLIB_libats_libc_all_in_one.html (linked from http://www.ats-lang.org/Libraries.html) and FILEptr_is_null is not there. But it is in

Re: Beginner's question: open and close file

2019-03-12 Thread Shimin Guo
On Tue, Mar 12, 2019 at 12:23 PM Hongwei Xi wrote: > Here is a quick fix: > extern > praxi > clear{a:t0ype}(x: INV(a)): void > > fun open_close(): void = > let > val fptr = fopen("hello.dats", file_mode_r) > val p = ptrcast(fptr) > in > if p = 0 > then > let > prval () =

Re: Beginner's question: open and close file

2019-03-12 Thread Vanessa McHale
FWIW, I personally would use FILEptr_is_null to check if fptr is null, rather than ptrcast and then a comparison to 0 On 3/12/19 2:22 PM, Hongwei Xi wrote: > Here is a quick fix: > extern > praxi > clear{a:t0ype}(x: INV(a)): void > > fun open_close(): void = > let >   val fptr =

Re: Beginner's question: open and close file

2019-03-12 Thread Hongwei Xi
Here is a quick fix: extern praxi clear{a:t0ype}(x: INV(a)): void fun open_close(): void = let val fptr = fopen("hello.dats", file_mode_r) val p = ptrcast(fptr) in if p = 0 then let prval () = FILEptr_free_null(fptr) in end else let val

Beginner's question: open and close file

2019-03-12 Thread Shimin Guo
I wrote the following code #include "share/atspre_define.hats" #include "share/atspre_staload.hats" staload "libats/libc/SATS/stdio.sats" fun open_close(): void = let val fptr = fopen("hello.dats", file_mode_r) val p = ptrcast(fptr) in if p = 0 then let prval () =