I'm sorry, I somehow forgot the essentials of Prolog. FWIW, I was trying to design a solution to a parser design problem mentioned by Gazdar & Mellish in "Natural language processing in Prolog" (1989) p. 253: "What implications do these issues have for chart parser implementation? First of all, they mean that destructive unification cannot be used in the generation of new edges [...] The obvious solution to these problems is to always use copies for unification." On Sat, Nov 14, 2009 at 1:56 AM, Kish Shen <kisshen_at_...5...> wrote: > -dp- wrote: > >> I need to search working memory with a query that contains a mixture of >> atoms and variables, and the functor and arity of the query will change >> (in >> a data-driven design). >> >> It's important that the contents of working memory not change as a result >> of >> such search, such as a variable being bound to an atom or compound term in >> the query. >> >> I haven't been able to find a predicate for non-destructive unification >> (e.g., it might keep bindings in one of its arguments), and my current >> best >> idea is to construct a dummy query with the same functor and arity but >> will >> all new free vars. After each successful destructive unification with a >> dummy query, I'd use my own non-destructive unification predicate to >> compare >> the found item with the real query. >> >> Is there an easier way to do this? >> >> Hi David, > > I am not sure I understand in detail what you are trying to do, but your > wording of the problem suggest you are not really thinking in a Prolog way > -- there is really no concept of "working memory", nor is unification > "destructive". I also don't really understand what your "search" is doing > exactly... > > For example, by working memory, do you mean runtime variables and their > bindings, or do you mean something else (e.g. clauses (including facts) in > your program)? > > If you are talking about variables that occur in your source fact/clauses > (your talk about queries seem to suggest this might be what you mean), then > these are not runtime variables, e.g. if I have the following fact in my > program, > > fact(1, A). > > then calling the query "fact(1, 3)" will not change the "A" in your program > source to 3, you can check this by calling fact/1 twice: > > fact(1,3), fact(1,New) > > New will remain uninstantiated. > > On the other hand, if you are talking about run-time terms, and you want to > compare two terms without binding any variables, you can use ==/2 to do > this. > > If you really need to perform unification, and you are only interested in > the result (i.e. success or failure), and you don't want to bind anything, > there is a well known Prolog trick of using \+/2 twice to do this, e.g.: > > \+ \+(A=B) > > Your question seem to suggest that you may not be very familiar with > programming in Prolog -- if this is so, you may want to read some textbook > on Prolog -- the points I mention should all be covered in any introductory > book on Prolog. > > Cheers, > > Kish >Received on Wed Nov 25 2009 - 10:25:07 CET
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST