in C/C++ or Java u would simply use X++; or X=X+1;
is there any trick how i can get that in prolog to work ???
please help!
Not really. [things about setarg/assert/backtracking ... omitted]
Perhaps you should tell us why you want that one variable X to be incremented and
why for your purposes something like NewX is X + 1 is not enough.
Cheers
Bart Demoen
> HI i know how to handle with the "is" operator so it is useless
> for a simple variable incrementation as X is X+1,
> I just want to increment a variable which has been instantiated once.
>
> in C/C++ or Java u would simply use X++; or X=X+1;
Right, in C, C++, or Java you would simply increment a "variable".
That thinking doesn't carry over to Prolog. A "variable" in Prolog is
not the same thing as a "variable" in C or any imperative language.
In logic programming, you are not so much telling your variables what
to do as what to be. Thus it makes no sense for the same variable to
have both the values N and N+1. (I'm omitting qualifiers about
backtracking and more abstruse mechanisms.)
> is there any trick how i can get that in prolog to work ???
> please help!
You're working against the language. The best help I can give you is
that you should work through a Prolog tutorial until you understand
how Prolog does things. My tutorial links are a bit old, but:
http://kti.ms.mff.cuni.cz/~bartak/prolog
http://www.loria.fr/~blackbur/
http://www.amzi.com/AdventureInProlog/advtoc.htm
http://spivey.oriel.ox.ac.uk/mike/logic/index.html
--
Tom Breton at panix.com, username tehom. http://www.panix.com/~tehom
You can't.
This is a matter matter of what programming paradigm you are using. In
Prolog you would use recursion for
tasks that are considered iterative in imperative languages. For instance to
count the members of a list:
% base case: empty list
count([],0).
% recursive
count([H|T],Count):-
count(T,CountR),
Count is CountR+1.
Regards Jesper
> In
> Prolog you would use recursion for
> tasks that are considered iterative in imperative languages. For instance to
> count the members of a list:
>
> % base case: empty list
> count([],0).
>
> % recursive
> count([H|T],Count):-
> count(T,CountR),
> Count is CountR+1.
Not necessarily. In Prolog you also use accumulators. E. g.,
count(List,Count) :-
count1(List,0,Count).
count1([],Count,Count).
count1([H|T],Subtotal0,Total) :-
Subtotal is Subtotal0 + 1,
count1(T,Subtotal,Total).
Best,
Bill
Regards,
Mary Kroening
Amzi! inc.
"PF" <julia...@freenet.de> wrote in message
news:1c6ee569.03122...@posting.google.com...
you have to use an accumulator, such as X1 is X + 1 then you pass the
accumulator on
i.e
increment(X,newX) :- newX is X + 1.