๐ง Logic: โ๏ธ `read_string/3` unify a stream to a string
bdeneux opened this issue ยท 0 comments
bdeneux commented
๐ Purpose
Implement a prolog predicate to read a given Stream
and unify it to String
. Optionally give a max length of reading, when stream reach the given length, the reading is stop. If Length is unbound, Stream is read to the end and Length is unified with the number of characters read.
๐งช Expected behavior
read_string(+Stream, ?Length, -String) is det
Where
Stream
: represent a streamLength
: is the max length to readString
: represent the unified read stream as string
๐ฏ Example
file_to_string(File, String, Length) :-
open(File, read, In),
read_string(In, Length, String),
close(Stream).
?- file_to_string('path/file/foo.txt', String, Length).
String = 'Hello World'
Length = 11
โ Acceptance Criteria
- The predicate is implemented according to the described behavior and examples
- The predicate passes all test cases
- Any related documentation is updated
๐ References and linked predicate
- SWI-Prolog : https://www.swi-prolog.org/pldoc/doc_for?object=read_string/3
open/4
#379