Compare commits
5 Commits
68aefc12c5
...
e05096734e
Author | SHA1 | Date | |
---|---|---|---|
|
e05096734e | ||
|
d132d3868f | ||
|
55ec480b62 | ||
|
8da33ba465 | ||
|
f39fa514a5 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
data.pl
|
4
data.pl
4
data.pl
@ -1,4 +0,0 @@
|
|||||||
task("take over a world",todo).
|
|
||||||
task("sleep",done).
|
|
||||||
task("finish this",todo).
|
|
||||||
task("test task",todo).
|
|
58
todo.pl
58
todo.pl
@ -1,26 +1,45 @@
|
|||||||
:- 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).
|
|
||||||
|
|
||||||
list :- all_tasks(L), print_task_list(L).
|
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).
|
||||||
|
|
||||||
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) :-
|
||||||
@ -45,17 +64,24 @@ 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),
|
||||||
asserta(Task),
|
Task = end_of_file,
|
||||||
load_task(Stream).
|
% write("reading last: "),
|
||||||
|
% 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(_, _)).
|
||||||
|
|
||||||
consult(data).
|
load.
|
Loading…
Reference in New Issue
Block a user