[Top][All Lists]

[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:24:46 -0500

On Tuesday, August 27, 2002, at 02:14  PM, address@hidden wrote:

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) :-
     copy_term(Term, TermCopy),
        my_clause(TermCopy) )
       -> true

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.

Oops. I changed the code but not the comment--I changed it to use var/1 instead of checking for groundness, since ground/1 isn't ISO and I'm too lazy to go find an implementation of ground/1 right now.

reply via email to

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