implement main
open core
classpredicates
copyLine :(inputStream I, outputStream O).
clauses
copyLine(I,O):-Line=I:readLine(),O:write(Line,"\n").
classpredicates
onClick:()procedure.
clauses
onClick():-InputFile= inputStream_file::openFile("c:\\test.txt"),OutputFile= outputStream_file::openFile("c:\\test2.txt"),
copyLine(InputFile,OutputFile),
copyLine(InputFile,OutputFile),OutputFile:writef("a="),/* insert other data in between*/
std::repeat(),
copyLine(InputFile,OutputFile),InputFile:endOfStream(),!,InputFile:close(),OutputFile:close().
onClick() .
clauses
run():-
console::init(),
onClick(),
succeed(). % place your own code hereend implement main
goal
mainExe::run(main::run).
%Write data to another file only when it is not the end of streamclasspredicates
copyLine :(inputStream I, outputStream O).
clauses
copyLine(I,O):-if not(I:endOfStream())thenLine=I:readLine(),O:write(Line,"\n")end if.
predicates
onPushButtonClick :button::clickResponder.
clauses
onPushButtonClick(_Source)= button::defaultAction:-InputFile= inputStream_file::openFile8("E:\\test.txt"),%use openFile8 instead of openFileOutputFile= outputStream_file::openFile8("E:\\test2.txt"),%use openFile8 instead of openFile
copyLine(InputFile,OutputFile),
copyLine(InputFile,OutputFile),OutputFile:writef("a="),/* insert other data in between*/
std::repeat(),
copyLine(InputFile,OutputFile),InputFile:endOfStream(),!,InputFile:close(),OutputFile:close().
onPushButtonClick(_Source)= button::defaultAction.
This code clearly expects that there are at least three lines in the file (copyLine is called three times before endOfStream is tested the first time).
I will definitely suggest a recursive solution instead of using a 'repeat' loop: