Check existence of clause 
Author Message
 Check existence of clause

Hi all! May I ask how to check if a clause exist, without going into
existence error? Currently, I'm using an extra clause as a guard, but I
wonder if there's any better or straightforward method.

Thanks in advance for any replies.

regards,
Hean Keong



Fri, 09 Jul 1999 03:00:00 GMT  
 Check existence of clause

Quote:

> Hi all! May I ask how to check if a clause exist, without going into
> existence error? Currently, I'm using an extra clause as a guard, but I
> wonder if there's any better or straightforward method.

> Thanks in advance for any replies.

> regards,
> Hean Keong

Hi,

first of all there is a difference between predicates that have no
definition and therefore are unknown to the system and those predicates
that have no clauses at the moment. The latter case is meaningful e.g.
for dynamic predicates (declared by dynamic/2). As far as I know calls
to predicates that have no clauses are not caught by the system. They
have to be controlled by user predicates.

I don't know what kind of Prolog system you are using, but SICStus
Prolog offers a particular system flag for undefined predicates. By
default this flag is set to 'error' raising an exception if an undefined
predicate is called. This flag can be changed using unknown/2 or
prolog_flag/3 so that any call to such a predicate e.g. simply fails.

Sincerely,
Dirk Richarz.

************************************************************************
  Dirk Richarz                    *
  University of Koblenz-Landau    *

  56075 Koblenz                   * phone: +49-261-9119-469
  Germany                         * fax:   +49-261-9119-465
************************************************************************



Sat, 10 Jul 1999 03:00:00 GMT  
 Check existence of clause

Quote:

>Hi all! May I ask how to check if a clause exist, without going into
>existence error? Currently, I'm using an extra clause as a guard, but I
>wonder if there's any better or straightforward method.

I assume that (1) you want to check if a clauses exists _without_ executing
(or calling it), (2) the clauses to check are static (if their are dynamic
you can use the built-in clause/2 predicate). I have the same need in
Logtalk (an object-oriented extension for Prolog that I'm developing) and I
too have not found other solution than using what you call guard clauses.
If you don't need code portability you may however find a Prolog compiler
that gives you access to the kind of information you need.

Regards,

Paulo

---------------------------------------------------------
Paulo Moura
Dep. of Mathematics, University of Coimbra, Portugal

http://www.ci.uc.pt/logtalk/pmoura.html
---------------------------------------------------------



Mon, 12 Jul 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Check existence of clause

2. How to check a given class for existence?

3. Checking for file existence in labview 6.1

4. Checking for the existence of a file.

5. Checking File Existence in Regina ReXX Win95

6. Checking for existence of directories

7. check for file/directory existence

8. Directory existence check

9. Check existence of dsname with wildcards

10. checking the existence of a fiel

11. Checking File Existence in Quintus PROLOG

12. Check for existence and then add to TreeCtrl

 

 
Powered by phpBB® Forum Software