View difference between Paste ID: WgNbBQwB and wKvK2S7k
SHOW: | | - or go back to the newest paste.
1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
2
%% library
3
4
use_module(library(assoc)).
5
6
proto((N, Slots), C, P) :- call(P, (H, Slots)), append([C], H, N).
7
8
root(([root], Slots)) :- empty_assoc(Slots).
9
10
add_attr((H, S), A, V, (H,N)) :- put_assoc(A, S, V, N).
11
12
set_attr(O, A, V, N) :-  add_attr(O, A, V, N).
13
14
get_attr((_, Slots), A, V) :- get_assoc(A, Slots, V).
15
16
isa(([C|_], _), C).
17-
isa(([_|Cs],_), C) :- write(Cs), isa((Cs,_), C).
17+
isa(([_|Cs],_), C) :- isa((Cs,_), C).
18
19
classof(([C|_],_), C).
20
21
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
%% usage
23
24
grand_parent(P) :- proto(P0, grand_parent, root),
25
	add_attr(P0, attr0, initial_value, P).
26
27
parent(P) :- proto(P0, parent, grand_parent),
28
	add_attr(P0, answer, 42, P).
29
30
son(P) :- proto(P0, son, parent),
31
	add_attr(P0, weight, 1, P).
32
33
new_son(P) :- son(P0), set_attr(P0, answer, 0, P).