Share Tips, Code Samples, etc. with the Visual Prolog community.
Steve Lympany
VIP Member
Posts: 56
Joined: 31 Mar 2001 23:01

external database "chain" object

Unread post by Steve Lympany »

Hi,
Here is a very simple class that I use when using the external database. The class is "adl_chain", and each adl_chain object is created with a chainDB and a chain name. When an object is created, you no longer have to ensure the chain name is correct. So instead of

Code: Select all

clauses        fred(ChainDB):-                 ChainDB:chain_inserta("chain_name",Term,Ref),
you would use:

Code: Select all

       fred(ADL_CHAIN):-                 ADL_CHAIN:chain_inserta(Term,Ref),
No, big deal, but it makes things a bit easier to control if you have many chains. The predicates are the same as chaindb, but the chain name is not required.

Here is the code.
File: adl_chain.i

Code: Select all

interface adl_chain     open core         domains                 chain_name=string.         predicates                 chain_inserta:(_ Term,chainDB::ref) procedure (i,o).                 chain_insertz:(_ Term,chainDB::ref) procedure (i,o).                 ref_term:(chainDB::ref,_) procedure (i,o).                 term_replace:(chainDB::ref,_ Term).                 term_delete:(chainDB::ref).                 chain_terms:(_ Term,chainDB::ref) nondeterm (o,o).                 p_chain_delete:().                 get_nth:(integer)->_ Term determ. end interface adl_chain
File: adl_chain.cl

Code: Select all

class adl_chain : adl_chain     open core   predicates     classInfo : core::classInfo.     % @short Class information  predicate.     % @detail This predicate represents information predicate of this class.     % @end constructors         new:(chaindb,chain_name).   end class adl_chain
File: adl_chain.pro

Code: Select all

implement adl_chain     open core   constants     className = "vip6pack/mychainDB/adl_chain".     classVersion = "".   clauses     classInfo(className, classVersion). facts         zz_db:chaindb:=erroneous.         zz_chain_name:chain_name:=erroneous. clauses         new(Chaindb,Chain_name):-                 zz_db:=ChainDB,                 zz_chain_name:=Chain_name. clauses         chain_inserta(Term,Ref):-                 zz_db:chain_inserta(zz_chain_name,Term,Ref). clauses         chain_insertz(Term,Ref):-                 zz_db:chain_insertz(zz_chain_name,Term,Ref). clauses         ref_term(Ref,Term):-                 zz_dB:ref_term(Ref, Term). clauses         term_replace(Ref,Term):-                 zz_db:term_replace(Ref,Term). clauses         term_delete(Ref):-                 zz_db:term_delete(zz_chain_name,Ref). clauses         chain_terms(Term,Ref):-                 zz_db:chain_terms(zz_chain_name,Term,Ref). clauses         p_chain_delete():-                 zz_db:chain_delete(zz_chain_name),                 fail.         p_chain_delete(). facts         zz_count:integer:=0. clauses         get_nth(N)=Term:-                 zz_count:=0,                 zz_db:chain_terms(zz_chain_name,Term,_Ref),                 zz_count:=zz_count+1,                 zz_count=N,!.                 end implement adl_chain
Post Reply