🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4142

Re: incrementing values

#4142
From: Jonathan Mills
Date: Fri, 02 Feb 1990 17:14
30 lines
1357 bytes
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.
Technical Details
Message-ID: <34731@iuvax.cs.indiana.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!iuvax!jwmills
References: <17467@megaron.cs.arizona.edu> <31462@shemp.CS.UCLA.EDU> <34699@iuvax.cs.indiana.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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