I am a beginner and am building main with a large number of fact databases that are used by many clauses. For organization purposes I would like to put all the assert clauses that build the databases into a different package, but I can't figure out how to make them visible to main.
Is there a way to declare class facts so that a database of class facts built in one package are available for use in a different package?
-
- Posts: 24
- Joined: 16 Jan 2021 1:33
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: Beginner question - declare class facts across packages
Facts can be declared only in a class's implementation (.pro file) so you cannot make the facts themselves visible outside that class. However, you can easily put predicate definitions to manipulate those facts in the class's .cl file or .i file(s) to make them accessible from other classes as in the example below:
For non-trivial applications, it is a good practice to put all the basic database manipulations into a class (e.g., myDataDB) that handles operations such as consulting, saving, exporting, ,backups, "tidying", etc. Then you create other classes that read or modify that database (e.g., myDataDB_Reporter, myDataDB_Loader ). This is a way of controlling the complexity of your code so it will be easier for you or others to maintain.
Code: Select all
class classA
open core
predicates
putFact : (integer).
getFact_nd : () -> integer nondeterm.
end class classA
Code: Select all
implement classA
open core
class facts
factInA : (integer).
clauses
putFact(I) :-
assert(factInA(I)).
getFact_nd() = I :-
factInA(I).
end implement classA
-
- Posts: 24
- Joined: 16 Jan 2021 1:33
Re: Beginner question - declare class facts across packages
Thanks, that answers my question. Now to move some code...