[mercury-users] Pred defns

David Powers powers at ist.flinders.edu.au
Tue Mar 31 11:14:06 AEST 1998



Fergus Henderson said:
> On 30-Mar-1998, Ralph Becket <rwab1 at cam.sri.com> wrote:
> > Just a word in my defence: while Fergus' syntax uses atoms to denote
> > accumulators and #x to refer to the current value of acc. x, my
> > expansion does indeed provide the same functionality:
> 
> Yes, indeed.  And thank you for your proposal, I do think it is quite nice.
> I'm just trying to make it a bit more "O'Keefe-proof" ;-)
> 
> > Personally I'd prefer keeping capitalised names for accumulators -
> > since this is a syntactic expansion before compilation it doesn't
> > really matter what you pick.

I agree with Fergus about the operators (leaving aside arguments about which 
symbols to use) and with Ralph about the capitalization.

Once we introduce the operator so that the accumulator never occurs unadorned, 
it IS acting as a VARIABLE and the construct is quite pure, being equivalent to 
being bound to [1|_] initially, [1,2|_] after its first increment, etc. with 
the initial state always being available as the head, and the current state 
always being available as the last bound term in the list, and next state being 
the head of the tail variable.  Such an implementation would mean that the 
value of the VARIABLE corresponds to the history of the accumulator - and if 
these operations are to be backtrackable that history must be preserved.   Note 
that internally it could be implemented as a difference list which would be 
quite efficient ([1,2|A]-[2|A], etc.), but the VARIABLE doesn't need to reflect 
the extra tracking information being kept around for efficiency.

This is essentially the same technique I used for implementing backtrackable 
hash tables for Sicstus years ago.  If backtracking/history is not 
required/used a more memory efficient structure can be (and was) used, but if 
the user wants to look in side while debugging, then the history version can be 
substituted for the interim.  I don't see why it shouldn't generalize to 
Mercury.

dP
-- 
--   powers at acm.org   http://www.cs.flinders.edu.au/people/David_Powers.html
 Associate Professor David M. W. Powers PhD     Facsimile:   +61-8-8201-3626
 Director, AI Lab, Dept of Computer Science	UniOffice:   +61-8-8201-3663
 The Flinders University of South Australia	Secretary:   +61-8-8201-2662
 GPO Box 2100 Adelaide South Australia 5001	PrvMobile:   +61-414-824-307





More information about the users mailing list