Compare commits

..

No commits in common. "e05096734e795aecc18da30aa8ccd833cbd6983e" and "68aefc12c5318ac782c3b206004519208c9c16a1" have entirely different histories.

3 changed files with 20 additions and 43 deletions

1
.gitignore vendored
View File

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

4
data.pl Normal file
View File

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

56
todo.pl
View File

@ -1,45 +1,26 @@
:- dynamic task/2.
:- dynamic requires/2.
:- dynamic idx/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).
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).
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 "),
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).
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) :-
@ -64,24 +45,17 @@ save :-
load_task(Stream) :-
read(Stream, Task),
Task \= end_of_file,
% write("reading: "),
% write(Task),
% nl,
asserta(Task),
load_task(Stream).
Task = end_of_file,
close(Stream).
load_task(Stream) :-
read(Stream, Task),
Task = end_of_file,
% write("reading last: "),
% write(Task),
close(Stream).
asserta(Task),
load_task(Stream).
load :-
open('data.pl', read, Stream),
load_task(Stream).
clear :- retractall(task(_, _)).
load.
consult(data).