Re: [eclipse-clp-users] Searching working memory without destructive unification?

From: Kish Shen <>
Date: Fri, 13 Nov 2009 17:56:14 +0000
-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.



This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Fri Nov 13 2009 - 17:56:28 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET