1

I am new to Eclipse, and I have been trying to read a file stream without success. The code that I normally use for this in SWI-Prolog is this:

read_until_stop(File, [L|Lines]) :-
    read_line_to_codes(File, Codes),
    Codes \= end_of_file,
    atom_codes(L, Codes),
    L \= stop,
    !,
    read_until_stop(File, Lines).
read_until_stop(_, []).

But read_line_to_codes is not available in Eclipse apparently. What is a good alternative for this?

picardo
  • 24,530
  • 33
  • 104
  • 151

2 Answers2

1

As suggested by the Eclipse manual the Eclipse counterpart would be

read_line(Stream, String) :-
    read_string(Stream, end_of_line, _Length, String).

with the difference that read_string returns the actual string as opposed to the list of codes, i.e., atom_codes is no longer necessary:

?- read_string(input, end_of_line, Length, String).
      abcdefghi
      Length = 9
      String = "abcdefghi"
      yes.
Alexander Serebrenik
  • 3,567
  • 2
  • 16
  • 32
1

I think read_line_to_codes/2 can easily be implemented in ECLiPSe, but for efficiency reuse available builtins. You can do with read_line/2.

Try to define

:- use_module(library(util)).
read_line_to_codes(S, L) :- read_line(S, L).

or simply call read_line...

CapelliC
  • 59,646
  • 5
  • 47
  • 90