-
Notifications
You must be signed in to change notification settings - Fork 1
/
la_strings.pl
60 lines (47 loc) · 1.22 KB
/
la_strings.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%% la_strings.pl
use_module(library(pio)).
use_module(library(dcg/basics)).
open_s(File,Mode,Stream) :-
atom_string(File1,File),
open(File1,Mode,Stream),!.
string_atom(String,Atom) :-
atom_string(Atom,String),!.
phrase_from_file_s(string(Output), String) :-
atom_string(String1,String),
phrase_from_file(string(Output), String1),!.
writeln1(Term) :-
term_to_atom(Term,Atom),
writeln(Atom),!.
write1(Term) :-
term_to_atom(Term,Atom),
write(Atom),!.
shell1_s(Command) :-
atom_string(Command1,Command),
shell1(Command1),!.
shell1(Command) :-
(bash_command(Command,_)->
true;
(writeln(["Failed shell1 command: ",Command]),abort)
),!.
bash_command(Command, Output) :-
setup_call_cleanup(process_create(path(bash),
['-c', Command],
[stdout(pipe(Out))]),
read_string(Out, _, Output),
close(Out)).
concat_list(A1,B):-
A1=[A|List],
concat_list(A,List,B),!.
concat_list(A,[],A):-!.
concat_list(A,List,B) :-
List=[Item|Items],
string_concat(A,Item,C),
concat_list(C,Items,B).
append_list(A1,B):-
A1=[A|List],
append_list(A,List,B),!.
append_list(A,[],A):-!.
append_list(A,List,B) :-
List=[Item|Items],
append(A,[Item],C),
append_list(C,Items,B).