jonasf@kuling.UUCP (Jonas Flygare) (07/04/88)
I would appreciate any help on implementing clause/2 in SBProlog, as it would provide a crude listing/1 facility in conjunction with bagof/3. If you are a serious user of SBProlog and have other useful predicates implemented, email me, please. (serious: Knows meaning and use of DCG & d-lists. Also WAM-level.. ;-)-- Jonas Flygare (aka Flax) +------------------------------------------+ email: jonasf@kuling.UUCP | "Never try to hack while a playful ferret | real: Vaktargatan 32 F:621 | is watching your toes. | S-754 22 Uppsala Sweden +-------- I TRIED....... OUCH! ------------+
debray@arizona.edu (Saumya Debray) (07/10/88)
In article <732@kuling.UUCP>, jonasf@kuling.UUCP (Jonas Flygare) writes: > I would appreciate any help on implementing clause/2 in SBProlog, > as it would provide a crude listing/1 facility in conjunction with > bagof/3. The main reason sbprolog doesn't have clause/2 or clause/3 is that in four years of working with Prolog, none of us really found a need for it in our work (which is not to say that they're useless, it's just that there were other, more immediately useful, things for us to work on). The system is currently undergoing a major overhaul to overcome some alignment restrictions that prevent the current version from being ported to machines like the Sun-4. We expect to include clause/2 and clause/3 in the next release (hopefully, within a month). Meanwhile, the following quick hack provides a poor man's clause/2 on sbprolog: cassert( Cl ) :- (Cl = (H :- B) -> true ; (H = Cl, B = true) ), assert(Cl), assert($clausedb(H,B)). clause(H, B) :- $clausedb(H, B). Predicates asserted through cassert/1 instead of assert/1 can be accessed through clause/2. It should be straightforward to add an option to consult/2 to make it call either assert/1 or cassert/1. (I admit this isn't a very efficient solution, since the work involved in asserting clauses is effectively being doubled. Like I said, it's a quick hack ...). -- Saumya Debray CS Department, University of Arizona, Tucson internet: debray@arizona.edu uucp: arizona!debray
ok@quintus.uucp (Richard A. O'Keefe) (07/11/88)
In article <6183@megaron.arizona.edu> debray@arizona.edu (Saumya Debray) writes: >In article <732@kuling.UUCP>, jonasf@kuling.UUCP (Jonas Flygare) writes: >> I would appreciate any help on implementing clause/2 in SBProlog ... >Meanwhile, the following quick hack provides a poor man's clause/2 on >sbprolog: [ He exhibits a variant of assert which stores two copies of the clause. ] A little bit of history may be of interest: one of the design goals of the Prolog system Lawrence Byrd and Bill Clocksin put together (which later became Bill Clocksin's Prolog-X) was that there shouldn't be any distinction between compiled and interpreted code. (This was '82, I think.) So the ZIP instructions had three modes: read, write, and copy. (This is similar to the techniques that ALS use, except they are WAM-based rather than ZIP-based.) However, it was found that this put too much of a burden on the compiler: it couldn't even optimise "p :- q, true, true" to "p :- q" because clause/[2,3] had to see the original code. (This is why my 1984 proposal for Prolog evaluable predicates specified that assert/1 _should_ be allowed to make this kind of change, by the way.) So eventually Bill Clocksin ended up compiling two copies of each and every clause (and assert/1 compiles). If I recall correctly, a specialised version of the compiler was created for unit clauses so that the second copy could be compiled faster, and of course that made life better for setof/3 as well. Oddly enough, ZIP code was very compact, so compiling two copies of a clause in Prolog-X took less space than asserting one copy in many other Prologs.