From 3cc96ed39b3d0bb45b28d4d261f355251d028566 Mon Sep 17 00:00:00 2001 From: Spaghettificated Date: Mon, 8 Jul 2024 15:17:08 +0200 Subject: [PATCH] impl unchecking (manually and by adding subtask) --- todo.pl | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/todo.pl b/todo.pl index d1a35c5..a2b2210 100644 --- a/todo.pl +++ b/todo.pl @@ -39,7 +39,8 @@ new(X) :- new(X,Y) :- idx(Y, Task), new(X, Task). new(X,Y) :- asserta(task(X, todo)), - asserta(requires(X, Y)), + asserta(requires(X, Y)), + uncheck(X), write("added task "), write(X), write(" as a subtask for "), @@ -52,10 +53,11 @@ depend(X,Y) :- asserta(requires(X, Y)). depend(X,Y) :- task(X, done), - task(Y, _), - retractall(task(Y, _)), - asserta(task(Y, todo)), - asserta(requires(X, Y)). + task(Y, todo), + uncheck(X). +depend(X,Y) :- + task(X, done), + task(Y, done). check(X) :- idx(X, Task), check(Task). check(X) :- @@ -75,11 +77,33 @@ check(X) :- 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). +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)),