Article View: comp.lang.prolog
Article #167Re: want a bagoff impl. without assert/retracts
From: Richard A. O'Keefe
Date: Thu, 09 Apr 1992 12:35
Date: Thu, 09 Apr 1992 12:35
43 lines
2275 bytes
2275 bytes
In article <5821@charon.cwi.nl>, kwakkel@cwi.nl (Fred Kwakkel) writes: > SWI prolog gives for the following query: > 1 ?- S=[1,2,3,X,4], bagof( Y, member( Y, S ), L ). > L = [1,2,3,G413,4] > S = [1,2,3,G325,4] > X = G325 > Y = G334 You have used bagof/3 outside its domain of definition. Different Prolog systems do different things, because bagof/3 was only ever defined to work when all the solutions are GROUND. > But I want L and S to be EXACTLY the same and NOT different > uninstantiated vars: Well, you could use Quintus Prolog, which goes to some trouble to put the original variables back. SICStus Prolog's bagof/3 is based on the same PD implementation, so it does what you want too. (That thud you just heard was the author of the PD implementation falling over from patting himself on the back too much. (:-)) But such a hack can only be justified on pragmatic grounds (= "paying customers want this frightful kluge"). > I think it means that I need a bagof implementation without assert/retracts. Nope, not at all. The PD implementation is based on assert/retract, and most "bubble-in-the-heap" findall/3 implementations I've heard of will introduce new variables too. What you need is something that collects solutions just like findall/3 then walks along them putting back the original variables whenever it is possible to do so. > I don't know how to write this, can you help me? Pick up the PD implementation from the Edinburgh Prolog library, available from the University of Edinburgh. The very best thing to do is to redesign your program so that it doesn't want to do this. Why do you want such a non-logical thing for? -- I am writing a book on debugging aimed at 1st & 2nd year CS students using C/Modula/Pascal-like languages. Please send suggestions (other than "you _must_ cite "C Traps and Pitfalls") to ok@goanna.cs.rmit.oz.au
Technical Details
Message-ID:
<10167@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!goanna!okReferences:
<5821@charon.cwi.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: want a bagoff impl. without assert/retracts Message-ID: <10167@goanna.cs.rmit.oz.au> Date: 9 Apr 92 12:35:16 GMT References: <5821@charon.cwi.nl> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 43