Prolog programs don't works
Author Message
Prolog programs don't works

Hello!!

I have one problem.

I most write program in prolog.
This problem is:

I have 6 military units and 6 soldier ( each have different status).
I most make a one formation, matrix, 6*6, which most
be, that in each row and each coloumn are one soldier from each status
and one soldier from each units.

I have and 1 programs, which do not works and they needs be fixed.
If any know results, please send me results.
I will be wery grateful.

The program is:

1.

end:-
write('Rankings from soldier are a,b,c,d,e i f, and military
units are 1,2,3,4,5 i 6.'), nl,
assert(count(1)), asserta(rankings(1, [a,b,c,d])),
asserta(unit(1, [1,2,3,4])),
begin, nl, write('Results is::'), nl, give(1,1),
retractall(rankings(X,Y)),
retractall(unit(X1,Y1)), retractall(count(N)),
retractall(warn(U,I,O,P)).

begin:- make_rankings, unit(1,N), mix(N,L), delete, assert(unit(1,L)),
begin1.
begin.

begin1:- make_unit, unit(1, List), mix(List, New), delete, find(New).

make_rankings:- count(N), rankings(N, List), N1 is N + 1, mix(List,
New),
asserta(rankings(N1,New)), retract(count(N)),
assert(count(N1)), N1<4, make_rankings.
make_rankings:- retractall(count(N)), assert(count(1)).

make_unit:- count(N), unit(N, List), N1 is N + 1, mix(List, New),
asserta(unit(N1,New)), retract(count(N)),
assert(count(N1)), N1<4, make_unit.
make_unit:- retractall(count(N)), assert(count(1)).

delete:- retractall(count(N)), retractall(warn(M,K,L,O)),
assert(count(1)).

unite([], X, X).
unite([X|Xr],Y,[X|Z]):-unite(Xr,Y,Z).

mix([],[]).
mix(L,[X|Xr]:- choose(X,L,Ost), mix(Ost,Xr).

choose(X,[X|Xr],Xr).
choose(X,[Y|Yr],[Y|Z]):- choose(X,Yr,Z).

unit), !, insert(rankingsovi, unitinice, N, 1),
!, retract(count(N)), N1 is N + 1, assert(count(N1)),
find(Tail).
find([]).

insert([Grankings|Rrankings],[Gunit|Runit], Row, Coloumn):-  not
warn(X,V, Grankings,Gunit), %not warn(W, Coloumn, U, Gunit),
assert(warn(Row, Coloumn, Grankings,Gunit)), Coloumn1 is
Coloumn + 1, insert(Rrankings, Runit, Row, Coloumn1).
insert([],[], Row, Coloumn).

give(Row, Coloumn):- Coloumn=<4, warn(Row, Coloumn, rankings, unit),
write(rankings), write(unit), tab(3),
Coloumn1 is Coloumn + 1, give(Row, Coloumn1).
give(Row, Coloumn):- nl, Row<4, Row1 is Row + 1, give(Row1, 1).
give(Row, Coloumn).

Mon, 11 Apr 2005 02:34:46 GMT
Prolog programs don't works

Quote:

> I most write program in prolog.

While looking at your program, I started thinking that you have submitted it
to the wrong news group: didn't you want to submit it to
comp.lang.<any dirty programming language in which you must use side effects> ?

So, here is my 2 cents of advice: if you really really must write a program in Prolog,
write one without all the side effects, submit that to this news group and then, I am sure,
you will get more help. And your grade at school will also improve.

Cheers

Bart Demoen

ps. just in case you have no clue what is wrong with your program: avoid assert/retract like the plague

Mon, 11 Apr 2005 04:07:48 GMT
Prolog programs don't works

Quote:

> > I most write program in prolog.

. . .
> So, here is my 2 cents of advice: if you really really must write a
program in Prolog,
> write one without all the side effects, submit that to this news group and
then, I am sure,
> you will get more help. And your grade at school will also improve.

> Cheers

> Bart Demoen

> ps. just in case you have no clue what is wrong with your program: avoid

assert/retract like the plague
I had the same reaction as Bart -- but in case you still don't know where to
start:
the unchanging facts (the names of the soldiers, the unit they belong to,
and their attribute)
are expressed as: facts!

The matrix would be expressed as a data structure that gets recursively
created by the clauses.
I would suggest you start with something simple, such as a list of triples
representing a sparse matrix.