Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!mailrus!ames!ig!arizona!debray From: debray@cs.arizona.edu (Saumya K. Debray) Newsgroups: comp.lang.prolog Subject: incrementing values Message-ID: <17467@megaron.cs.arizona.edu> Date: 2 Feb 90 03:52:55 GMT Organization: U of Arizona CS Dept, Tucson Lines: 29 This is an excerpt from an article posted recently to another newsgroup: | > the most frequently occuring construct in any programming language is | > equivalent to the construct x += 1 | | Er, not quite *any* programming language. I have been programming | professionally in Prolog for the last five years, and I need to do | this sort of thing maybe once or twice a year. | | BTW, here's how to do it: | | increment(Variable) :- | retract(value(Variable, OldValue)), | NewValue is OldValue + 1, | assert(value(Variable, NewValue)). | | ..., increment(x), ... | | but as this makes two modifications to the database and is therefore | pretty expensive (not to mention poor style), you don't want to do it | too often. Comments? -- Saumya Debray CS Department, University of Arizona, Tucson internet: debray@cs.arizona.edu uucp: uunet!arizona!debray