commit 68aefc12c5318ac782c3b206004519208c9c16a1 Author: Spaghettificated Date: Thu Jul 4 03:32:04 2024 +0200 first commit diff --git a/data.pl b/data.pl new file mode 100644 index 0000000..6a1298c --- /dev/null +++ b/data.pl @@ -0,0 +1,4 @@ +task("take over a world",todo). +task("sleep",done). +task("finish this",todo). +task("test task",todo). \ No newline at end of file diff --git a/todo.pl b/todo.pl new file mode 100644 index 0000000..c445d1c --- /dev/null +++ b/todo.pl @@ -0,0 +1,61 @@ +:- dynamic task/2. +:- dynamic requires/2. +:- discontiguous load/0. + +task("take over a world", todo). +task("sleep", done). +task("finish this", todo). + +all_tasks(L):- findall(X, task(X, _), L). +all_tasks(L, STATE):- findall(X, task(X, STATE), L). + +print_task_list([]). +print_task_list([H|T]) :- task(H,ISDONE), write(ISDONE),write(': '), write(H),nl, print_task_list(T). + +list :- all_tasks(L), print_task_list(L). + +print_list([]). +print_list([H|T]) :- write(H),nl, print_list(T). + +new(X) :- asserta(task(X, todo)), write("added task "), +write(X). +check(X) :- task(X, todo), asserta(task(X, done)), retractall(task(X, todo)), +write("marked task "), write(X), write(" as done"). + + +save_task(Task, Stream) :- + task(Task, State), + write_canonical(Stream, task(Task, State)), + write(Stream, '.'). + +save_task_list([Task], Stream) :- + save_task(Task, Stream). + +save_task_list([H|T], Stream) :- + save_task(H, Stream), + write(Stream, '\n'), + save_task_list(T, Stream). + +save :- + all_tasks(L), + open('data.pl', write, Stream), + save_task_list(L, Stream), + close(Stream). + + +load_task(Stream) :- + read(Stream, Task), + Task = end_of_file, + close(Stream). + +load_task(Stream) :- + read(Stream, Task), + asserta(Task), + load_task(Stream). +load :- + open('data.pl', read, Stream), + load_task(Stream). + +clear :- retractall(task(_, _)). + +consult(data). \ No newline at end of file