0
votes

I want to implement a while loop for example: while(true) {(assign(n,1));(assign(r,2));} in prolog. The example can be considered as what happens in OO language such as java while true it will assign n as 1 and r as 2. How do I implement such predicates in prolog where more than one predicate must be executed when while is true. I want my predicate to be something like

while(true,[(assign(n,1)),(assign(r,2))].
1
Here you see Prolog too much as an "imperative" language. The idea of a "logical language" is that one typically does not create programs with a lot of "doing", but more with "declaring"/"defining". Typically you do not want the assignments to be overwritten, etc. - Willem Van Onsem
Prolog doesn't have these imperative features built-in, but I wrote an interpreter for imperative algorithms in Prolog as a proof-of-concept. - Anderson Green

1 Answers

0
votes

Hmm interesting question. Why you no just write it down like you wanna write down?

while(X, Y) :-
    X, Y.

I try and write this down and when I wrote it then I wrote this and it worked?

?- while(true, (format("hello, ", []), format("sailor", []))).
hello, sailor
true.