Page 1 of 1

Beginner question - declare class facts across packages

Posted: 21 Mar 2021 14:54
by dcgreenwood
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?

Re: Beginner question - declare class facts across packages

Posted: 21 Mar 2021 15:30
by Harrison Pratt
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:

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
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.

Re: Beginner question - declare class facts across packages

Posted: 22 Mar 2021 16:21
by dcgreenwood
Thanks, that answers my question. Now to move some code...