implement indexes
This commit is contained in:
parent
d132d3868f
commit
e05096734e
40
todo.pl
40
todo.pl
@ -2,9 +2,6 @@
|
|||||||
:- dynamic requires/2.
|
:- dynamic requires/2.
|
||||||
:- dynamic idx/2.
|
:- dynamic idx/2.
|
||||||
:- discontiguous load/0.
|
:- 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):- 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).
|
||||||
@ -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 :- 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) :-
|
||||||
write(X).
|
asserta(task(X, todo)),
|
||||||
check(X) :- task(X, todo), asserta(task(X, done)), retractall(task(X, todo)),
|
write("added task "),
|
||||||
write("marked task "), write(X), write(" as done").
|
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) :-
|
save_task(Task, Stream) :-
|
||||||
@ -57,16 +64,19 @@ 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),
|
||||||
write("reading: "),
|
Task = end_of_file,
|
||||||
write(Task),
|
% write("reading last: "),
|
||||||
nl,
|
% write(Task),
|
||||||
asserta(Task),
|
close(Stream).
|
||||||
load_task(Stream).
|
|
||||||
|
|
||||||
load :-
|
load :-
|
||||||
open('data.pl', read, Stream),
|
open('data.pl', read, Stream),
|
||||||
@ -74,4 +84,4 @@ load :-
|
|||||||
|
|
||||||
clear :- retractall(task(_, _)).
|
clear :- retractall(task(_, _)).
|
||||||
|
|
||||||
consult(data).
|
load.
|
Loading…
Reference in New Issue
Block a user