first commit
This commit is contained in:
commit
68aefc12c5
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).
|
61
todo.pl
Normal file
61
todo.pl
Normal file
@ -0,0 +1,61 @@
|
||||
:- dynamic task/2.
|
||||
:- dynamic requires/2.
|
||||
:- 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, 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_list([]).
|
||||
print_list([H|T]) :- write(H),nl, print_list(T).
|
||||
|
||||
new(X) :- asserta(task(X, todo)), write("added task "),
|
||||
write(X).
|
||||
check(X) :- task(X, todo), asserta(task(X, done)), retractall(task(X, todo)),
|
||||
write("marked task "), write(X), write(" as done").
|
||||
|
||||
|
||||
save_task(Task, Stream) :-
|
||||
task(Task, State),
|
||||
write_canonical(Stream, task(Task, State)),
|
||||
write(Stream, '.').
|
||||
|
||||
save_task_list([Task], Stream) :-
|
||||
save_task(Task, Stream).
|
||||
|
||||
save_task_list([H|T], Stream) :-
|
||||
save_task(H, Stream),
|
||||
write(Stream, '\n'),
|
||||
save_task_list(T, Stream).
|
||||
|
||||
save :-
|
||||
all_tasks(L),
|
||||
open('data.pl', write, Stream),
|
||||
save_task_list(L, Stream),
|
||||
close(Stream).
|
||||
|
||||
|
||||
load_task(Stream) :-
|
||||
read(Stream, Task),
|
||||
Task = end_of_file,
|
||||
close(Stream).
|
||||
|
||||
load_task(Stream) :-
|
||||
read(Stream, Task),
|
||||
asserta(Task),
|
||||
load_task(Stream).
|
||||
load :-
|
||||
open('data.pl', read, Stream),
|
||||
load_task(Stream).
|
||||
|
||||
clear :- retractall(task(_, _)).
|
||||
|
||||
consult(data).
|
Loading…
Reference in New Issue
Block a user