users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question on assert and retract


From: spratt
Subject: Re: question on assert and retract
Date: Tue, 27 Aug 2002 14:14:46 -0500

On Tuesday, August 27, 2002, at 01:31  PM, bruno patin wrote:

But now, as listing is not an iso-prolog directive how not to add the same facts two times ?

Perhaps my_assertz:

my_assertz(Term) :-
     (var(Term)
       ;
     copy_term(Term, TermCopy),
        my_clause(TermCopy) )
       -> true
     ;
     assertz(Term).

my_clause( Term ) :-
     Term =.. [ (:-), Head, Body]
       -> clause(Head, Body)
     ;
     clause(Term, true).

This only assertz's Term if Term is ground (i.e. contains no unbound variables) and is not unifiable with a clause already in the clause database.

This predicate may raise an exception in some Prolog systems if Term refers to a non-interpreted predicate, due to the use of clause/2.

and has assertz the same comportment in other prolog implementations ?

Yes, I believe so.

-lindsey





reply via email to

[Prev in Thread] Current Thread [Next in Thread]