Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!agate!violet.berkeley.edu!lagache From: lagache@violet.berkeley.edu (Edouard Lagache) Newsgroups: comp.lang.prolog Subject: Destructive predicates (random musings - part-I). Message-ID: <7289@agate.BERKELEY.EDU> Date: 1 Mar 88 07:10:40 GMT Sender: usenet@agate.BERKELEY.EDU Reply-To: lagache@violet.berkeley.edu (Edouard Lagache) Organization: University of California, Berkeley Lines: 59 Keywords: Destructive predicates, LISP vs PROLOG Philosophy >In article <710@cresswell.quintus.UUCP>, ok@quintus.UUCP >(Richard A. O'Keefe) writes (on replaca in PROLOG): > >Oh dear oh dear oh dear oh dear. Have you ever felt that >everything you have done for the last N years has been >futile? Have you ever been telling people about the milk >and honey of the Promised Land, only to have them turn >around and say "What about leeks? We had great leeks in >Egypt." ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Hmmmmm, Doesn't seem that sympathetic to the idea, but at least Dr. O'Keefe is keeping an open mind !!!!!!!!!!!!!!! Okay, okay, I agree that 'replaca' isn't such a good idea. I forgot to make the old declarative test, and sure enough if it hard to imagine what reversing the fields (i.e. replaca(X,Y,[junk,b,c,d]), instead of replaca(junk,[a,b,c],Z) ) would mean declaratively. Still, that is not quite what I was curious about. For example, suppose we had a destructive append. Obviously this cannot be implemented with respect to other PROLOG primitives, so the actual machine implementation could be make reversible. (i.e. append([a,b,c],X,Y) would do what regular append does but append([a,b,c],[d],Z) would destructively bash [a,b,c] with [d] and store it in Z). Ah, but you reply, what would happen upon backtracking, or more importantly suppose the problem is append(A,B,C) where A = [a,b], and B = [c]. Well, we don't have to take destructive list bashing too seriously and could allow ourselves copies of A and B. That would allow us to solve both the backtracking and A,B messed up pointer problem. Even in this case we would save some number of copies (length of B copies of A to be exact in "standard" append). But of course that is what Quintus (and every self respecting PROLOG) does - right? Well, then aren't we allowing an okay form of destructive list bashing? If this isn't okay - well, why not? This point not withstanding, what would be wrong with having a "fully" destructive append that would be used only in the situations without reversibility and backtracking. So what if I save only a penny - what did Ben Franklin say about a penny in time ....... I guess there is something more fundamental here. There is a tension here between "the function soup" of LISP, and the comparative austerity of the (standard) PROLOG predicate library. Implementation issues aside (for the moment), each approach has some merits, but PROLOG tends for force the programmer to sacrifice "simple decomposition" for efficiency. What is "simple decomposition"? Well, I better save that for my next note - stay tuned! Edouard Lagache