Example:
- Dallas
- Boston
- Houston
- Chicago
- Dallas
- Houston
Code: Select all
implement main
open core, console, string
class predicates
write_list : (outputStream, string*).
read_list : (inputStream, string*) anyflow.
pr2 : (integer, string*, string*) nondeterm anyflow.
pr1 : (string*, string*) nondeterm anyflow.
clauses
read_list(In, []) :-
In:endOfStream(),
In:close(),
!.
read_list(In, [H | T]) :-
H = In:readLine(),
read_list(In, T).
write_list(_, []).
write_list(Out, [H | Tail]) :-
Out:write(H, "\n"),
write_list(Out, Tail).
pr2(X, L2, L1) :-
N = X,
L1 = list::filter(L2, { (E) :- not(N = string::length(E)) })
or
fail.
pr1([H | T], L2) :- error c609 : Variable 'L2' is not completely bound
L3 = L2, %error c609 : Variable 'L3' is not completely bound
L4 = list::append(L3, [H]),
N = length(H),
!,
pr2(N, T, L1),
pr1(L1, L4)
or
fail.
pr1([], []) :-
!.
run() :-
init(),
In = inputStream_file::openFile8("InFile.txt"),
read_list(In, L),
pr1(L, L2),
write(L2),
nl,
Out = outputStream_file::create8("OutFile.txt"),
write_list(Out, L2),
_ = readLine(),
!
or
console::write("Fail"),
_ = readLine().
end implement main
goal
mainExe::run(main::run).