How to trim file length in Prolog?

How to trim file length in Prolog?

I found only the predicate set_stream_position/2 in the ISO standard. But I do not find the set_stream_length/2 predicate in the main Prolog systems.

Similarly, the position/1 stream property exists, but I do not see the length/1 stream property anywhere. The latter will help to use set_stream_length/2 .

What will be the workaround?

Bye

+4
source share
1 answer

I think I get it!

see this page ...

change after the comment @false, here is a sketch of the encapsulating code:

 set_file_size(Path, Size) :- setup_call_cleanup( open(Path, update, S), ( stream_property(S, reposition(true)), % stream_property(S, position(Q)), % set_stream_position(S, Q), seek(S, Size, bof, Size), set_end_of_stream(S) ), close(S)). 

It works, but relies on seek / 4 builtin. I cannot fully determine the status of such compliance with the WRT ISO requirements. It is renamed to ISO IO, but does not meet the requirements ...

Those two commented lines served me to check the opaque position of the / 1 position. To request stream_position_data values

+2
source

All Articles