Hard Prolog Question :) ( at least for me ) 
Author Message
 Hard Prolog Question :) ( at least for me )

Hello all Logic Programmers !

I am trying to add to my database a circular fact.
I would need to do that with an "assert" , but it doesn't seem to work.
Do You think there is another way to do that?
For example imagine You have to assert a thing like this one :

?- X=f(X),assert(X).

The unification of course works for the not making of the occour check but
then it takes a non finite time to assert X .
This could mean that prolog interpreters treat differently variables
during the unification ( X=f(f(f(f(f(..)))))) ) , and during the assert
(X=f(f(f( really infinite f(f)) )))) , but I already started speaking about
things I totally ignore , so i better stop here and wait for Your enlighting
follow-ups or replies...
Thanks ...
--
  *********************************************************************
  *          Alessio Lomuscio           * "I testi non fanno testo"   *

  *********************************************************************



Fri, 12 Jul 1996 18:56:22 GMT  
 Hard Prolog Question :) ( at least for me )

Quote:
> I am trying to add to my database a circular fact.

It is implementation dependant if cyclic terms are supported or not. I
don't think the ISO proposal says anything about this except for
unification.

SICStus Prolog supports cyclic terms in assert and copy_term since
release 2.1#7.

--
Stefan Andersson

Tel: +46 8 752 15 61  Ttx: 812 6154 7039 SICS S  Fax: +46 8 751 72 30



Fri, 12 Jul 1996 21:11:24 GMT  
 Hard Prolog Question :) ( at least for me )

Quote:
>For example imagine You have to assert a thing like this one :

>?- X=f(X),assert(X).

In this very case you can assert a rule instead of a fact. As you cannot
assert any clauses for =/2 anyway, assume you want to do
        ?- X=f(X), assert(p(X)).
Instead, you can then call
        ?- assert((p(X) :- X = f(X))).
This clause has no cyclic subterms but when you call p(X), the cyclic term
is created.

--Micha

---
Micha Meier                     ------------------------------------------------
ECRC, Arabellastr. 17           The opinions expressed above are private
D-81925 Munich 81               and may not reflect those of my employer.



Fri, 12 Jul 1996 23:14:25 GMT  
 Hard Prolog Question :) ( at least for me )
You could of course:
        assert( X = foo(X) )
and unify only when needed...

-----------------------------------------
Alan S Westwood            LPA Ltd
                           Studio 4 RVPB
                           Trinity Road
                           Wandsworth
                           LONDON
Email:                     SW18 3SX



Sat, 13 Jul 1996 00:30:02 GMT  
 Hard Prolog Question :) ( at least for me )
Precisely, that is what I meant, what I sent was a typo!

-----------------------------------------
Alan S Westwood            LPA Ltd
                           Studio 4 RVPB
                           Trinity Road
                           Wandsworth
                           LONDON
Email:                     SW18 3SX



Sat, 13 Jul 1996 22:21:51 GMT  
 Hard Prolog Question :) ( at least for me )
Quote:
> This could mean that prolog interpreters treat differently variables
> during the unification ( X=f(f(f(f(f(..)))))) ) , and during the assert

[...]

I don't think so. Have you tried

        ?- X=f(X), Y=f(Y), X=Y.

I guess this will also loop endlessly.

Bye,
        Jens.

--


---------------------------------+---------------------------------------------
As the air to a bird, or the sea to a fish, so is contempt to the contemptible.



Sun, 14 Jul 1996 00:04:15 GMT  
 Hard Prolog Question :) ( at least for me )
Or more precisely
        ?- assert( fact( X = foo(X) ) ).

Then we can write:
        ?- fact(X), X.  or call( X )
etc.
-----------------------------------------
Alan S Westwood            LPA Ltd
                           Studio 4 RVPB
                           Trinity Road
                           Wandsworth
                           LONDON
Email:                     SW18 3SX



Sun, 14 Jul 1996 01:53:30 GMT  
 Hard Prolog Question :) ( at least for me )

Quote:

>For example imagine You have to assert a thing like this one :
>?- X=f(X),assert(X).

The most obvious solution ( at least for me ) is : you should not
do things like this!! :-)

Just curious.  Why do you need to do this?  Very likely there is something
wrong in your program specification/design.



Sun, 14 Jul 1996 00:19:06 GMT  
 Hard Prolog Question :) ( at least for me )

Quote:

>I am trying to add to my database a circular fact.
>?- X=f(X),assert(X).

If you are using a Prolog system which advertises its ability to handle
"Rational Trees" or "Cyclic Terms", fine.  Otherwise, expect to have a
really hard time with this.  The reason is very simple, and not at all
what you think.

The best thing to do is to store a clause which creates the term.
For your example:

        assert((  f(X) :- X = f(X)  ))

If you know a good algorithm for finding "cheap" places to break cycles
in a term, plublish it and then maybe some Prolog implementors will use
it.

My personal opinion is that cyclic terms are a snare of the devil and
that there is _always_ a better way to solve your real problem.
--

In Victoria, if a burglar injures himself breaking into your house,
_he_ can sue _you_ under the Occupiers' Liability Act 1983.  Nice one, pols!



Mon, 15 Jul 1996 15:23:37 GMT  
 Hard Prolog Question :) ( at least for me )

Quote:


>>For example imagine You have to assert a thing like this one :

>>?- X=f(X),assert(X).

>The most obvious solution ( at least for me ) is : you should not
>do things like this!! :-)

>Just curious.  Why do you need to do this?  Very likely there is something
>wrong in your program specification/design.

Personally,  I'd go with  f(X_in,X_out), assert(X_out),  or even to simply
incorporate the assert/ clause into the f(X).  Then again, my C programs
don't always work.

Bruce Irvin

--
   The opinions expressed are not necessarily those of the University of
     North Carolina at Chapel Hill, the Campus Office for Information
        Technology, or the Experimental Bulletin Board Service.
           internet:  laUNChpad.unc.edu or 152.2.22.80



Tue, 16 Jul 1996 21:33:56 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Hard Prolog Questions

2. The Harder You Work, the Less You Will Earn

3. intel manuals hard copy (little offtopic)

4. The Harder You Work, the Less You Will Earn

5. The Harder You Work, the Less You Will Earn

6. 1 little, 2 little, 3 little endians...

7. Wanted: simple NP-hard problems in Prolog

8. Hard disk problems - Hard ones :))

9. Hard disk I/O the hard way

10. Understanding Prolog (a little better)

11. little prolog projects

12. So many Prologs, so little time....

 

 
Powered by phpBB® Forum Software