Author(s): Angel Fernandez Pineda.
Version: 1.3#120 (1999/11/26, 12:5:17 MET)
Version of last change: 1.3#66 (1999/9/30, 13:19:4 MEST)
This chapter will explain error reporting when declaring a class. The first section will explain compile-time errors, this is, any semantic error which may be determined at compile time. The second section will explain run-time errors, this is, any exception that may be raisen by the incorrect usage of O'CIAO. Some of those errors may be not reported at compile time, due to the use of meta-programational structures. For example:
functor(X,my_method,0),call(X).
O'CIAO is not able to check whether my_method/0 is a valid method or not. So, this kind of checking is left to run time.
:- meta_predicate example(addmodule).
example(X,FromModule) :- call(FromModule:X).
:- data attr.
:- dynamic attr(_).
:- data attr/m.
etc,etc...
attr(initial_value).
:- data attr/1.
It is a must to declare attributes before any clause of the given predicate.
:- multifile example/2.
Multifile predicates must be declared before any clause of the given predicate.
:- data my_attribute/1.
my_attribute(X) :- X>=0 , X<=2.
This is not allowed since attributes are assumed to hold simple facts. The correct usage for those initialization clauses is:
:- data my_attribute/1.
my_attribute(0).
my_attribute(1).
my_attribute(2).
:- public(p/1).
:- multifile(p/1).
This is not allowed since multifile predicates are not related to Object Oriented Programming.
data/1
declaration. You must declare at least one clause for every virtual method. Virtual attributes does not require any clause but a
data/1
declaration must be present.
implements/1
declaration present at your code where given Module is not declared as class nor interface.
implements/1
declaration.
public/1
declaration for F/A, but there is no definition for it at current class nor an inherited one.
self(abc)
.
asserta_fact(inherited(not_an_attribute(8)))
where not_an_attribute/1 was not declared as data or dynamic by the super-class (or corresponding ascendant).
:- meta_predicate attr(goal).
:- data attr/1.
There is no sense in declaring an attribute as meta-predicate.
:- class(myclass). :- inherit_class(other_class). myclass :- other_class.
O'CIAO works in conjunction with the habitual CIAO Prolog module system, which also reports its own error messages. This will cause CIAO to report a little criptic error messages due to the general mechanism of source-to-source expansion. Those are some tips you must consider when compiling a class:
WARNING: (lns 28-30) [Item,Itema] - singleton variables in obj$remove/2
This error is relative to method remove/1.
set_prolog_flag/1
declaration will be usefull when declaring multiple constructors. It will avoid some awful warnings. Example:
:- class(myclass). %% Use this declaration whenever several constructors are needed. :- set_prolog_flag(multi_arity_warnings,off). myclass(_). myclass(_,_). :- set_prolog_flag(multi_arity_warnings,on).
class_error
):- use_module(library(class_error)).
Go to the first, previous, next, last section, table of contents.