Path: utzoo!mnetor!uunet!husc6!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: Destructive predicates (random musings - part-I). Message-ID: <772@cresswell.quintus.UUCP> Date: 14 Mar 88 07:50:33 GMT References: <7289@agate.BERKELEY.EDU> <716@sandino.quintus.UUCP> <1797@sics.se> Organization: Quintus Computer Systems, Mountain View, CA Lines: 24 Keywords: Destructive predicates, LISP vs PROLOG Philosophy In article <1797@sics.se>, alf@sics.se (Thomas Sj|land) writes: > More bluntly put: A D-list is not an object in the Herbrand domain. Right! This is why I think it is a bad idea to use Front-Back or Front\Back to package the two ends of a difference list as a single object, and try always to use two separate arguments in my programs. However, there is an encapsulation which works nicely, due I think to Stuart Shieber, which Fernando Pereira told me about. use q(0, X, X) for an empty list and q(s(s(...(0)...)), [X1,...,Xn|X], X) for a list of N elements. empty_queue(q(0,X,X)). queue_first(X, q(s(N),[X|Front],Back), q(N,Front,Back)). queue_last(X, q(s(N),Front,Back), q(N,Front,[X|Back])). queue_first(X, Queue1, Queue0) is analogous to List1 = [X|List0] queue_last( X, Queue1, Queue0) is similar but works at the other end.