Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!ames!ig!arizona!debray From: debray@cs.arizona.edu (Saumya K. Debray) Newsgroups: comp.lang.prolog Subject: Re: incrementing values Keywords: optimization, mangle Message-ID: <17483@megaron.cs.arizona.edu> Date: 2 Feb 90 15:05:23 GMT References: <17467@megaron.cs.arizona.edu> <31462@shemp.CS.UCLA.EDU> <34699@iuvax.cs.indiana.edu> Organization: U of Arizona CS Dept, Tucson Lines: 22 In article <34699@iuvax.cs.indiana.edu>, jwmills@iuvax.cs.indiana.edu (Jonathan Mills) writes: > | increment(Variable) :- > | retract(value(Variable, OldValue)), > | NewValue is OldValue + 1, > | assert(value(Variable, NewValue)). > > Retract/modify/assert sequences such as this can be optimized to > destructive assignment. A clever implementation can turn the whole > clause into an indexed increment in 68K machine language. At rather high expense, I would think. You have to ensure, for example, that no other predicate can have its hands on value/2 when increment/1 is invoked -- the analysis looks hairy. Somehow "X1 is X+1" seems so much simpler! -- Saumya Debray CS Department, University of Arizona, Tucson internet: debray@cs.arizona.edu uucp: uunet!arizona!debray