annotate itlstd.pl @ 20:07d6c4c5654b iso-prolog

SICStus v4 (ISO prolog syntax)
author kono
date Thu, 30 Aug 2007 14:16:36 +0900
parents 1c57a78f1d98
children 29cf617f49db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
1 /*
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
2 Copyright (C) 1991, Shinji Kono, Sony Computer Science Laboratory, Inc.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
3 The University, Newcastle upton Tyne
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
4
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
5 Everyone is permitted to copy and distribute verbatim copies
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
6 of this license, but changing it is not allowed. You can also
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
7 use this wording to make the terms for other programs.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
8
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
9 send your comments to kono@csl.sony.co.jp
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
10 $Header$
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
11 */
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
12
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
13 % ITL standarization
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
14 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
15 % Wed Jun 19 12:11:29 BST 1991
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
16 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
17 % a standard form of ITL, based on subterm classification
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
18 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
19 % P = \Sum Pn & Px
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
20 % Q = \Sum Qn & Qx
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
21 % P & Q = empty,Pn,Qn ; ( Px = Qx = true)
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
22 % more,Pn,Qn & Qx; ( Px = true )
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
23 % more,Pn,(Px & Q)
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
24 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
25 subterm_init :-
20
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
26 r_abolish(sb,3),
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
27 asserta((sb(-1,[],[]))),
20
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
28 r_abolish(sbn,1),
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
29 asserta(sbn(0)),
20
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
30 r_abolish(itl_state,2),
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
31 assertz(itl_state((['->'([],false)]),false)),
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
32 assertz(itl_state((['->'([],true)]),0)),!.
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
33
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
34
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
35 std_check(I,J,N) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
36 sb(N,I,J),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
37 std_check(I,J,N1) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
38 retract(sbn(N)),N1 is N+1,asserta(sbn(N1)),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
39 assertz(sb(N1,I,J)),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
40
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
41 itlstd(P,List) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
42 setof(N,subterm(P,N),List),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
43
20
07d6c4c5654b SICStus v4 (ISO prolog syntax)
kono
parents: 2
diff changeset
44 subterm(P,'->'(C,T)) :-
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
45 subterm(P,T,[],C0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
46 sortC(C0,C).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
47
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
48 % bubble sort
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
49 sortC([],[]).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
50 sortC([H|T],[Min|Y]):-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
51 min(T,H,Min,Rest),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
52 sortC(Rest,Y).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
53
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
54 min([],X,X,[]).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
55 min([H|T],X,Y,[H|S]) :- ord(H,X),!,min(T,X,Y,S).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
56 min([H|T],X,Y,[X|S]) :- min(T,H,Y,S).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
57
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
58 ord(not(X),not(Y)) :- !,X @> Y.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
59 ord(X,not(Y)) :- !,X @> Y.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
60 ord(not(X),Y) :- !,X @> Y.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
61 ord(X,Y) :- !,X @> Y.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
62
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
63 subterm(true,true,C,C):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
64 subterm(false,false,C,C):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
65 subterm(P,V,C,C1) :- atomic(P),!, local(V,P,C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
66 subterm(up(P),V,C,C1) :- !, local(V,up(P),C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
67 subterm(down(P),V,C,C1) :- !, local(V,down(P),C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
68 subterm((false&_),false,C,C) :-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
69 subterm((_&false),false,C,C) :-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
70 subterm((P&Q),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
71 std_check(P,Q,N),local(V,N,C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
72 subterm(@(Q),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
73 std_check(@(Q),'$$$',N),local(V,N,C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
74 subterm(^(Q),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
75 std_check(^(Q),'$$$',N),local(V,N,C,C1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
76 subterm((P,Q),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
77 subterm(P,PV,C,C0),subterm(Q,QV,C0,C1), and(PV,QV,V).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
78 subterm((P;Q),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
79 subterm(P,PV,C,C0),subterm(Q,QV,C0,C1), or(PV,QV,V).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
80 subterm(not(P),V,C,C1) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
81 subterm(P,PV,C,C1),negate(PV,V).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
82 % end %