For this test case gzip_ascii in package zlib
Here an open and close are used without call_cleanup/2
gzopen('plunit-tmp.gz', write, ZOut, [type(text), encoding(utf8)]),
set_stream(ZOut, newline(posix)),
format(ZOut, '~s', [ReferenceCodes]),
close(ZOut)
The documentation states
Do not use call_cleanup/2 if you perform side-effects prior to calling that will be undone by Cleanup. Instead, use setup_call_cleanup/3 with an appropriate first argument to perform those side-effects.
Is it correct that format(ZOut, '~s', [ReferenceCodes])
is a side effect and the reason call_cleanup/2 is not used?
Here an open and close are used with call_cleanup/2 as expected.
gzopen('plunit-tmp.gz', read, ZIn, [type(text), encoding(utf8)]),
set_stream(ZIn, newline(posix)),
call_cleanup(read_stream_to_codes(ZIn, Codes), close(ZIn))
In general should call_cleanup/2 or others predicates of the same intention be used with any open and close of a stream/file?
Currently I equate this concept to C# using statement with resources. Is that a valid way to begin to understand this concept?