-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlinda.pl
61 lines (48 loc) · 1.02 KB
/
linda.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
:- module(linda, [
linda_eval/1, linda_eval/2,
out/1,
in_noblock/1, rd_noblock/1,
in/1, rd/1,
bagof_in_noblock/3,
bagof_rd_noblock/3
]).
:- dynamic(linda/1).
linda_call_(H, G) :-
G,
H = G,
out(H).
linda_eval(Goal) :-
copy_term(Goal, Goal2),
call_task(linda_call_(_, Goal2)).
linda_eval(Head, Goal) :-
copy_term(Goal, Goal2),
call_task(linda_call_(Head, Goal2)).
out(Tuple) :-
assertz('$linda'(Tuple)),
yield.
in_noblock(Tuple) :-
retract('$linda'(Tuple)).
rd_noblock(Tuple) :-
'$linda'(Tuple).
in(Tuple) :-
once(retract('$linda'(Tuple))).
in(Tuple) :-
yield,
in(Tuple).
rd(Tuple) :-
'$linda'(Tuple).
rd(Tuple) :-
yield,
rd(Tuple).
turn_(Free^Generator, Functor, Goal) :-
!,
turn_(Generator, Functor, Goal2),
Goal = Free^Goal2.
turn_(Generator, Functor, Goal) :-
Goal =.. [Functor,Generator].
bagof_in_noblock(Template, Tuple, Bag) :-
turn_(Tuple, in_noblock, Goal),
bagof(Template, Goal, Bag).
bagof_rd_noblock(Template, Tuple, Bag) :-
turn_(Tuple, rd_noblock, Goal),
bagof(Template, Goal, Bag).