Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!umich!ox.com!itivax!dhw From: dhw@itivax.iti.org (David H. West) Newsgroups: comp.lang.prolog Subject: Re: incrementing values Message-ID: <4884@itivax.iti.org> Date: 2 Feb 90 19:32:52 GMT References: <17467@megaron.cs.arizona.edu> <31462@shemp.CS.UCLA.EDU> <34699@iuvax.cs.indiana.edu> <17483@megaron.cs.arizona.edu> Reply-To: dhw@itivax.UUCP (David H. West) Organization: Industrial Technology Institute Lines: 15 In article <17483@megaron.cs.arizona.edu> debray@cs.arizona.edu (Saumya K. Debray) writes: >> | increment(Variable) :- >> | retract(value(Variable, OldValue)), >> | NewValue is OldValue + 1, >> | assert(value(Variable, NewValue)). >Somehow "X1 is X+1" seems so much simpler! Indeed. But neither X nor X1 can be global, so you can sometimes end up adding pairs of extra arguments to clauses just to provide a data path for each such variable. If this spans enough levels, it may be worth using the admittedly ugly database method above. I've used it to quickly add and remove clause-invocation counting. -David West dhw@iti.org