Compare commits
No commits in common. "44ae363f58c1c18ca77f2a2de5eb84029f8305e0" and "e05096734e795aecc18da30aa8ccd833cbd6983e" have entirely different histories.
44ae363f58
...
e05096734e
118
todo.pl
118
todo.pl
@ -6,11 +6,7 @@
|
|||||||
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(X):-
|
|
||||||
task(X,ISDONE),
|
|
||||||
write(ISDONE),
|
|
||||||
write(': '),
|
|
||||||
write(X).
|
|
||||||
print_task_list([],_).
|
print_task_list([],_).
|
||||||
print_task_list([H|T],N) :-
|
print_task_list([H|T],N) :-
|
||||||
M is N+1,
|
M is N+1,
|
||||||
@ -18,8 +14,10 @@ print_task_list([H|T],N) :-
|
|||||||
asserta(idx(N, H)),
|
asserta(idx(N, H)),
|
||||||
write(N),
|
write(N),
|
||||||
write(". "),
|
write(". "),
|
||||||
print_task(H),
|
task(H,ISDONE),
|
||||||
nl,
|
write(ISDONE),
|
||||||
|
write(': '),
|
||||||
|
write(H),nl,
|
||||||
print_task_list(T, M).
|
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).
|
||||||
@ -30,129 +28,33 @@ 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) :-
|
|
||||||
task(X, todo),
|
|
||||||
write("task already exist"),
|
|
||||||
!.
|
|
||||||
new(X) :-
|
new(X) :-
|
||||||
asserta(task(X, todo)),
|
asserta(task(X, todo)),
|
||||||
write("added task "),
|
write("added task "),
|
||||||
write(X).
|
write(X).
|
||||||
new(X,Y) :- idx(Y, Task), new(X, Task).
|
|
||||||
new(X,Y) :-
|
|
||||||
asserta(task(X, todo)),
|
|
||||||
asserta(requires(X, Y)),
|
|
||||||
uncheck(X),
|
|
||||||
write("added task "),
|
|
||||||
write(X),
|
|
||||||
write(" as a subtask for "),
|
|
||||||
write(X).
|
|
||||||
depend(X,Y) :- idx(X, Task), depend(Task, Y).
|
|
||||||
depend(X,Y) :- idx(Y, Task), depend(X, Task).
|
|
||||||
depend(X,Y) :-
|
|
||||||
task(X, todo),
|
|
||||||
task(Y, _),
|
|
||||||
asserta(requires(X, Y)).
|
|
||||||
depend(X,Y) :-
|
|
||||||
task(X, done),
|
|
||||||
task(Y, todo),
|
|
||||||
uncheck(X).
|
|
||||||
depend(X,Y) :-
|
|
||||||
task(X, done),
|
|
||||||
task(Y, done).
|
|
||||||
|
|
||||||
check(X) :- idx(X, Task), check(Task).
|
|
||||||
check(X) :-
|
check(X) :-
|
||||||
task(X, todo),
|
task(X, todo),
|
||||||
\+ (requires(Y, X), task(Y,todo)),
|
|
||||||
asserta(task(X, done)),
|
asserta(task(X, done)),
|
||||||
retractall(task(X, todo)),
|
retractall(task(X, todo)),
|
||||||
write("marked "),
|
write("marked "),
|
||||||
write(X),
|
write(X),
|
||||||
write(" as done"),
|
write(" as done").
|
||||||
!.
|
check(X) :- idx(X, Task), check(Task).
|
||||||
check(X) :-
|
|
||||||
task(X, todo),
|
|
||||||
(requires(Y, X), task(Y,todo)),
|
|
||||||
write("you need to do "),
|
|
||||||
write(Y),
|
|
||||||
write(" before doing "),
|
|
||||||
write(X),
|
|
||||||
!.
|
|
||||||
check(X) :-
|
|
||||||
task(X, done),
|
|
||||||
write("the task is already done "),
|
|
||||||
!.
|
|
||||||
check(X) :-
|
|
||||||
\+ task(X, todo),
|
|
||||||
write("no such task as "),
|
|
||||||
write(X).
|
|
||||||
|
|
||||||
indent(0).
|
|
||||||
indent(N):-
|
|
||||||
write(" "),
|
|
||||||
M is N-1,
|
|
||||||
indent(M).
|
|
||||||
|
|
||||||
tree_branch([],_).
|
|
||||||
tree_branch([X|T],N):-
|
|
||||||
indent(N),
|
|
||||||
print_task(X),
|
|
||||||
nl,
|
|
||||||
findall(Y, requires(Y,X), L),
|
|
||||||
M is N+1,
|
|
||||||
tree_branch(L,M),
|
|
||||||
tree_branch(T,N).
|
|
||||||
tree(X):- task(X,_), tree_branch([X],0).
|
|
||||||
tree(X):- idx(X,Y), tree(Y).
|
|
||||||
|
|
||||||
uncheck(X) :- idx(X, Task), uncheck(Task).
|
|
||||||
uncheck(X):-
|
|
||||||
task(X, done),
|
|
||||||
retractall(task(X, done)),
|
|
||||||
asserta(task(X, todo)),
|
|
||||||
write("unchecked task: "),
|
|
||||||
write(X),
|
|
||||||
nl,
|
|
||||||
findall(Parent, requires(X, Parent), L),
|
|
||||||
uncheck_list(L).
|
|
||||||
uncheck_list([]).
|
|
||||||
uncheck_list([H|T]):-
|
|
||||||
task(H, todo),
|
|
||||||
uncheck_list(T).
|
|
||||||
uncheck_list([H|T]):-
|
|
||||||
uncheck(H),
|
|
||||||
uncheck_list(T).
|
|
||||||
|
|
||||||
save_requirement(T1, T2, Stream) :-
|
|
||||||
requires(T1, T2),
|
|
||||||
write_canonical(Stream, requires(T1,T2)),
|
|
||||||
write(Stream, '.\n').
|
|
||||||
save_requirement_list(T2, [T1], Stream) :-
|
|
||||||
save_requirement(T1, T2, Stream).
|
|
||||||
save_requirement_list(T2,[H|T], Stream) :-
|
|
||||||
save_requirement(H, T2, Stream),
|
|
||||||
save_requirement_list(T2, T, Stream).
|
|
||||||
save_task_requirements(Task, Stream) :-
|
|
||||||
findall(X, requires(X, Task), L),
|
|
||||||
save_requirement_list(Task, L, Stream).
|
|
||||||
save_task_requirements(Task, _) :- \+ requires(_, Task).
|
|
||||||
|
|
||||||
|
|
||||||
save_task(Task, Stream) :-
|
save_task(Task, Stream) :-
|
||||||
task(Task, State),
|
task(Task, State),
|
||||||
write_canonical(Stream, task(Task, State)),
|
write_canonical(Stream, task(Task, State)),
|
||||||
write(Stream, '.\n'),
|
write(Stream, '.').
|
||||||
save_task_requirements(Task, Stream).
|
|
||||||
|
|
||||||
save_task_list([Task], Stream) :-
|
save_task_list([Task], Stream) :-
|
||||||
save_task(Task, Stream).
|
save_task(Task, Stream).
|
||||||
|
|
||||||
save_task_list([H|T], Stream) :-
|
save_task_list([H|T], Stream) :-
|
||||||
save_task(H, Stream),
|
save_task(H, Stream),
|
||||||
|
write(Stream, '\n'),
|
||||||
save_task_list(T, Stream).
|
save_task_list(T, Stream).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
save :-
|
save :-
|
||||||
all_tasks(L),
|
all_tasks(L),
|
||||||
open('data.pl', write, Stream),
|
open('data.pl', write, Stream),
|
||||||
|
Loading…
Reference in New Issue
Block a user