Closed mndrix closed 10 years ago
Perhaps refactor head_tail/3 so that it can use read_line_to_string/2 or read_pending_input/3 for acquiring data from a stream. The former is perfect for lines/2 while the latter is ideal for codes/2 (lazy list of all character codes in a stream). In that case, the non-backtracking list stores "chunks" of data. The lazy list assembles those chunks into a single, long list.
lines/2 only works on streams that allow set_stream_position/2. It also leaves a trailing choicepoint when calling length/2 or maplist/2. Both of these problems are fixed by the following code. Write failing tests for the problems and then use this code to implement lines/2.
Also consider using the non-backtrackable list trick in a patch for library(pure_input).