From e05096734e795aecc18da30aa8ccd833cbd6983e Mon Sep 17 00:00:00 2001 From: Spaghettificated Date: Mon, 8 Jul 2024 11:29:10 +0200 Subject: [PATCH] implement indexes --- todo.pl | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/todo.pl b/todo.pl index 9f5d18b..c2cb4a6 100644 --- a/todo.pl +++ b/todo.pl @@ -2,9 +2,6 @@ :- dynamic requires/2. :- dynamic idx/2. :- discontiguous load/0. - -task_input(X, Y) :- task(X, Y). -task_input(X, Y) :- idx(X, Task), task(Task, Y). all_tasks(L):- findall(X, task(X, _), L). all_tasks(L, STATE):- findall(X, task(X, STATE), L). @@ -25,14 +22,24 @@ print_task_list([H|T],N) :- list_all :- all_tasks(L), print_task_list(L,1). list_all :- all_tasks(L), print_task_list(L,1). +list :- all_tasks(L, todo), print_task_list(L,1). +list_done :- all_tasks(L, done), print_task_list(L,1). 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"). +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 "), + write(X), + write(" as done"). +check(X) :- idx(X, Task), check(Task). save_task(Task, Stream) :- @@ -57,16 +64,19 @@ save :- load_task(Stream) :- read(Stream, Task), - Task = end_of_file, - close(Stream). + Task \= end_of_file, +% write("reading: "), +% write(Task), +% nl, + asserta(Task), + load_task(Stream). load_task(Stream) :- read(Stream, Task), - write("reading: "), - write(Task), - nl, - asserta(Task), - load_task(Stream). + Task = end_of_file, +% write("reading last: "), +% write(Task), + close(Stream). load :- open('data.pl', read, Stream), @@ -74,4 +84,4 @@ load :- clear :- retractall(task(_, _)). -consult(data). \ No newline at end of file +load. \ No newline at end of file