Compare commits

...

5 Commits

Author SHA1 Message Date
Spaghettificated
e05096734e implement indexes 2024-07-08 11:29:10 +02:00
Spaghettificated
d132d3868f ignore data.pl 2024-07-08 09:01:35 +02:00
Spaghettificated
55ec480b62 ignore data.pl 2024-07-08 08:51:01 +02:00
Spaghettificated
8da33ba465 add .gitignore 2024-07-08 08:14:47 +02:00
Spaghettificated
f39fa514a5 add some printing messages 2024-07-08 07:34:39 +02:00
3 changed files with 43 additions and 20 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
data.pl

View File

@ -1,4 +0,0 @@
task("take over a world",todo).
task("sleep",done).
task("finish this",todo).
task("test task",todo).

56
todo.pl
View File

@ -1,26 +1,45 @@
:- dynamic task/2. :- dynamic task/2.
:- dynamic requires/2. :- dynamic requires/2.
:- dynamic idx/2.
:- discontiguous load/0. :- 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):- findall(X, task(X, _), L).
all_tasks(L, STATE):- findall(X, task(X, STATE), 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_task_list([],_).
print_task_list([H|T],N) :-
M is N+1,
retractall(idx(N, _)),
asserta(idx(N, H)),
write(N),
write(". "),
task(H,ISDONE),
write(ISDONE),
write(': '),
write(H),nl,
print_task_list(T, M).
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([]).
print_list([H|T]) :- write(H),nl, print_list(T). 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). write(X).
check(X) :- task(X, todo), asserta(task(X, done)), retractall(task(X, todo)), check(X) :-
write("marked task "), write(X), write(" as done"). 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) :- save_task(Task, Stream) :-
@ -45,17 +64,24 @@ save :-
load_task(Stream) :- load_task(Stream) :-
read(Stream, Task), read(Stream, Task),
Task = end_of_file, Task \= end_of_file,
close(Stream). % write("reading: "),
% write(Task),
% nl,
asserta(Task),
load_task(Stream).
load_task(Stream) :- load_task(Stream) :-
read(Stream, Task), read(Stream, Task),
asserta(Task), Task = end_of_file,
load_task(Stream). % write("reading last: "),
% write(Task),
close(Stream).
load :- load :-
open('data.pl', read, Stream), open('data.pl', read, Stream),
load_task(Stream). load_task(Stream).
clear :- retractall(task(_, _)). clear :- retractall(task(_, _)).
consult(data). load.