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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| :- use_module(library('http/thread_httpd')).
:- use_module(library('http/html_write')).
:- use_module(library('http/http_session')).
:- use_module(library('http/http_error')).
:- dynamic systeme/1.
:- dynamic panne/1.
:- dynamic procedure/1.
procedure(procedure1):-panne(panne1).
procedure(procedure2):-panne(panne2).
procedure(procedure3):-panne(panne3).
procedure(procedure4):-panne(panne4).
panne(panne1):-systeme(systeme1).
panne(panne2):-systeme(systeme1).
panne(panne3):-systeme(systeme2).
panne(panne4):-systeme(systeme2).
%sibling(X,Y) :- parent(Z,X), parent(Z,Y).
%parent(X,Y) :- father(X,Y).
%parent(X,Y) :- mother(X,Y).
%%mother(trude, sally).
%father(tom, sally).
%father(tom, erica).
%father(mike, tom).
%female(trude).
%male(tom).
%male(mike).
% Checks so that the user doesn't try and do things he or she shouldn't
%check(sibling(_,_)).
%check(parent(_,_)).
%check(mother(_,_)).
check(systeme(_)).
check(panne(_)).
check(procedure(_)).
%check((X,Y)) :- check(X), check(Y).
%check((X;Y)) :- check(X), check(Y).
check('!').
go(Get) :-
% Get the query from the GET request
(member(q=Sys,Get);
member(p=Sys,Get)),
% Convert to a term
catch(atom_to_term(Sys, Term, Bindings),_,fail),
nonvar(Term),
% Check user has supplied a valid query
check(Term),
!,
% Find all solutions
forall(Term, (bind(Bindings), write(Term), nl)),
!.
pan(Get) :-member(ps=Pan,Get),
% Convert to a term
catch(atom_to_term(Pan, Term, Bindings),_,fail),
nonvar(Term),
% Check user has supplied a valid query
check(Term),
!,
% Find all solutions
forall(Term, (bind(Bindings), write(Term), nl)),
!.
% This binds a Variable=Name list so that unbound variables are bound to their Name
bind([]).
bind([A=A|T]) :-
!,
bind(T).
bind([_|T]) :-
bind(T).
/*<html>
<head></head>
<body>
<!-- Work out what the query was -->
<?, (member(q=Sys,Get);
member(p=Sys,Get);Sys='No Systeme Supplied') ,?>
<!-- Show the query -->
Query:
<pre>
<?= Sys ?>
</pre>
<!-- Show the solutions -->
Solutions:
<pre>
<?, once(
go(Get)
;
?>Error: Invalid Term (The query must be a valid prolog query)<?
)
,?></pre></pre>
<pre>
<form id="form1" name="form1" method="GET" action="msg2.prolog">
<p>
<label>
<input type="radio" name="q" value="systeme1" />
systeme1</label>
<br />
<label>
<input type="radio" name="p" value="systeme2" />
systeme2</label>
<br /><input type="submit" value="valider" >
</p>
</form>
<form id="form1" name="form1" method="GET" action="msg2.prolog">
<?,assert(systeme(Sys)),?><?,forall(panne(X),?><label>
<input type="radio" name="ps" value="<?=X?>" />
<?=X?></label><input type="submit" value="valider" ><br><?),?>
</form>
<form id="form1" name="form1" method="GET" action="msg2.prolog">
<?,retractall(panne(Pan)),assert(panne(Pan)),?> <?,forall(procedure(Y),?><label>
<input type="radio" name="pr" value="<?=Y?>" />
<?=Y?></label><br><?),?><input type="submit" value="valider" >
</form>
</pre>
</body>
</html>*/ |
Partager