axone-protocol/axoned

๐Ÿง  Logic: โ›“๏ธ `read_string/3` unify a stream to a string

bdeneux opened this issue ยท 0 comments

๐Ÿ“ 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 stream
  • Length: is the max length to read
  • String: 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