Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!iuvax!jwmills From: jwmills@iuvax.cs.indiana.edu (Jonathan Mills) Newsgroups: comp.lang.prolog Subject: Re: incrementing values Keywords: optimization, mangle Message-ID: <34731@iuvax.cs.indiana.edu> Date: 2 Feb 90 17:14:46 GMT References: <17467@megaron.cs.arizona.edu> <31462@shemp.CS.UCLA.EDU> <34699@iuvax.cs.indiana.edu> Reply-To: jwmills@iuvax.cs.indiana.edu (Jonathan Mills) Organization: Indiana University, Bloomington Lines: 30 In article <34699@iuvax.cs.indiana.edu> I wrote: > >Thus increment/1 could be implemented as: > >increment(Variable) :- > > clause(VarList,true), > arg(Variable,VarList,Value), > NewValue is Value + 1, > mangle(Variable,VarList,NewValue). > VarList must be wrapped inside a predicate, but, even worse, mangle doesn't modify clauses. It does modify passed structures, so the correct way to implement increment/1 using mangle is to attach a list of variables as yet-another-argument, and pass it to increment (which now becomes increment/2). This works under the "old" ALS for the Macintosh: demo :- X = vars(0,0,0,0,0), increment(1,X), write(X). increment(V,VarStruc) :- arg(V,VarStruc,X), Y is X + 1, mangle(V,VarStruc,Y). Other variations are possible; error checking on the index V would be helpful.