implement indexes

This commit is contained in:
Spaghettificated 2024-07-08 11:29:10 +02:00
parent d132d3868f
commit e05096734e

38
todo.pl
View File

@ -3,9 +3,6 @@
:- 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 "),
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").
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).
load.