Compare commits
No commits in common. "e05096734e795aecc18da30aa8ccd833cbd6983e" and "68aefc12c5318ac782c3b206004519208c9c16a1" have entirely different histories.
e05096734e
...
68aefc12c5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
data.pl
|
|
4
data.pl
Normal file
4
data.pl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
task("take over a world",todo).
|
||||||
|
task("sleep",done).
|
||||||
|
task("finish this",todo).
|
||||||
|
task("test task",todo).
|
58
todo.pl
58
todo.pl
@ -1,45 +1,26 @@
|
|||||||
:- 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).
|
||||||
|
|
||||||
print_task_list([],_).
|
list :- all_tasks(L), print_task_list(L).
|
||||||
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) :-
|
new(X) :- asserta(task(X, todo)), write("added task "),
|
||||||
asserta(task(X, todo)),
|
write(X).
|
||||||
write("added task "),
|
check(X) :- task(X, todo), asserta(task(X, done)), retractall(task(X, todo)),
|
||||||
write(X).
|
write("marked task "), write(X), write(" as done").
|
||||||
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) :-
|
||||||
@ -64,24 +45,17 @@ save :-
|
|||||||
|
|
||||||
load_task(Stream) :-
|
load_task(Stream) :-
|
||||||
read(Stream, Task),
|
read(Stream, Task),
|
||||||
Task \= end_of_file,
|
Task = end_of_file,
|
||||||
% write("reading: "),
|
close(Stream).
|
||||||
% write(Task),
|
|
||||||
% nl,
|
|
||||||
asserta(Task),
|
|
||||||
load_task(Stream).
|
|
||||||
|
|
||||||
load_task(Stream) :-
|
load_task(Stream) :-
|
||||||
read(Stream, Task),
|
read(Stream, Task),
|
||||||
Task = end_of_file,
|
asserta(Task),
|
||||||
% write("reading last: "),
|
load_task(Stream).
|
||||||
% 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(_, _)).
|
||||||
|
|
||||||
load.
|
consult(data).
|
Loading…
Reference in New Issue
Block a user