<commit_before>:- module(
  io_ext,
  [
    read_input_to_atom/2,   % +Source, -A
    read_input_to_codes/2,  % +Source, -Cs
    read_input_to_string/2, % +Source, -S
    write_output_to_atom/2, % :Goal_1, -A
    write_stream_to_file/2, % +Source, +Sink
    write_stream_to_file/3  % +Source, +Sink, +Opts
  ]
).
:- reexport(library(readutil)).

/** <module> Input/output or source/sink extensions

Predicates that extend the swipl builtin I/O predicates operating on streams.

@author <NAME>
@version 2015/08, 2015/10-2015/11, 2016/01-2016/02, 2016/04
*/

:- use_module(library(os/open_any2)).
:- use_module(library(readutil)).
:- use_module(library(yall)).

:- meta_predicate
    write_output_to_atom(1, -).





%! read_input_to_atom(+Source, -A) is det.

read_input_to_atom(Source, A) :-
  read_input_to_codes(Source, Cs),
  atom_codes(A, Cs).



%! read_input_to_codes(+Source, -Cs) is det.

read_input_to_codes(Source, Cs) :-
  call_on_stream(Source, {Cs}/[In,M,M]>>read_stream_to_codes(In, Cs)).



%! read_input_to_line(+Source, -Cs) is nondet.

read_input_to_line(Source, Cs) :-
  call_on_stream(Source, {Cs}/[In,M,M]>>read_input_to_line(In, Cs)).



%! read_input_to_string(+Source, -S) is det.

read_input_to_string(Source, S) :-
  read_input_to_codes(Source, Cs),
  string_codes(S, Cs).



%! write_output_to_atom(:Goal_1, -A) is det.
% Is called as `call(Goal_1, Out)`.

write_output_to_atom(Goal_1, A) :-
  setup_call_cleanup(
    new_memory_file(Handle),
    (
      setup_call_cleanup(
        open_memory_file(Handle, write, Out),
        call(Goal_1, Out),
        close(Out)
      ),
      memory_file_to_atom(Handle, A)
    ),
    free_memory_file(Handle)
  ).
<commit_msg>ADDED: Convenience predicate read_line_to_atom/2.<commit_after>:- module(
  io_ext,
  [
    read_input_to_atom/2,   % +Source, -A
    read_input_to_codes/2,  % +Source, -Cs
    read_input_to_string/2, % +Source, -S
    read_line_to_atom/2,    % +Source, -A
    write_output_to_atom/2, % :Goal_1, -A
    write_stream_to_file/2, % +Source, +Sink
    write_stream_to_file/3  % +Source, +Sink, +Opts
  ]
).
:- reexport(library(readutil)).

/** <module> Input/output or source/sink extensions

Predicates that extend the swipl builtin I/O predicates operating on streams.

@author <NAME>
@version 2015/08, 2015/10-2015/11, 2016/01-2016/02, 2016/04-2016/05
*/

:- use_module(library(os/open_any2)).
:- use_module(library(readutil)).
:- use_module(library(yall)).

:- meta_predicate
    write_output_to_atom(1, -).





%! read_input_to_atom(+Source, -A) is det.

read_input_to_atom(Source, A) :-
  read_input_to_codes(Source, Cs),
  atom_codes(A, Cs).



%! read_input_to_codes(+Source, -Cs) is det.

read_input_to_codes(Source, Cs) :-
  call_on_stream(Source, {Cs}/[In,M,M]>>read_stream_to_codes(In, Cs)).



%! read_input_to_line(+Source, -Cs) is nondet.

read_input_to_line(Source, Cs) :-
  call_on_stream(Source, {Cs}/[In,M,M]>>read_input_to_line(In, Cs)).



%! read_input_to_string(+Source, -S) is det.

read_input_to_string(Source, S) :-
  read_input_to_codes(Source, Cs),
  string_codes(S, Cs).



%! read_line_to_atom(+Source, -A) is det.

read_line_to_atom(Source, A) :-
  read_line_to_codes(Source, Cs),
  atom_codes(A, Cs).



%! write_output_to_atom(:Goal_1, -A) is det.
% Is called as `call(Goal_1, Out)`.

write_output_to_atom(Goal_1, A) :-
  setup_call_cleanup(
    new_memory_file(Handle),
    (
      setup_call_cleanup(
        open_memory_file(Handle, write, Out),
        call(Goal_1, Out),
        close(Out)
      ),
      memory_file_to_atom(Handle, A)
    ),
    free_memory_file(Handle)
  ).

{'fraction_non_alphanumeric': 0.1520110957004161, 'fraction_numerical': 0.02940360610263523, 'mean_word_length': 3.9195088676671213, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5353285', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1475, 'n_words': 240}