🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2850

alternative to trail stack?

#2850
From: dennis
Date: Fri, 30 Oct 1987 06:49
43 lines
2366 bytes
I have been examining various prolog implementations
and I see that all of them continue to use a trail stack
to record variable bindings that must be undone on
backtrack.

An entry on the trail
stack records the transition of a variable from unbound to bound.
From this I deduce that a variable will never appear
more than once on the trail stack at any given point in time.

If this deduction is true, then
it seems to me that one could replace the trail stack
by a trail chain threaded thru the variables in the heap
and in the environment (i.e., non-prototypical variables).

This would be implemented in the obvious way:
1. every variable has two parts: a binding value,
   and a trail chain pointer.
2. every environment (actually, only backtrack environments)
   have a pointer to the top of the chain at the point of
   the environment's creation.
3. trailing a variable consists of storing the current trail top
   into the trail pointer for the variable, and making the trail
   top point to this variable.  In other words, we link
   the variable into the front of the trail chain.
4. Untrailing just steps down the chain, unbinding the variables
   and setting their trail pointers to nil.

The cost over a trail stack is the doubling of space
used for variables and the time to link the variable into
the chain.  On a typical 32 bit machine, both of these costs
seem insignificant.

The advantage, of course, is that one of the prolog stacks
is eliminated, and that makes memory management simpler.

I assume that this idea has occurred to others,
but since none of the implementations I have seen use it,
I have a feeling that there is some obvious flaw.
If so, can someone please explain it to me?

Dennis Heimbigner
dennis@boulder.colorado.edu
Technical Details
Message-ID: <2764@sigi.Colorado.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!ames!hao!boulder!dennis

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!ames!hao!boulder!dennis
From: dennis@boulder.UUCP
Newsgroups: comp.lang.prolog
Subject: alternative to trail stack?
Message-ID: <2764@sigi.Colorado.EDU>
Date: Fri, 30-Oct-87 01:49:24 EST
Article-I.D.: sigi.2764
Posted: Fri Oct 30 01:49:24 1987
Date-Received: Sat, 31-Oct-87 19:53:32 EST
Sender: news@sigi.Colorado.EDU
Reply-To: dennis@boulder.Colorado.EDU ()
Distribution: world
Organization: University of Colorado, Boulder
Lines: 43