Previous Up Next
5 Syntax of TCLP declarations

5.1 Syntax of types

type ::= symbol( type , ... , type )
  | symbol
  | variable
symbol : a prolog atom, which corresponds to a type constructor
variable : a prolog variable, which corresponds to a type parameter

5.2 Type declaration
:- order Type1(A1, ... , AM) < Type2(B1, ... , BN)
Declares that the type constructor Type1 is smaller than the type constructor Type2. The mapping are given by the arguments, i.e. if AI == BJ then the I-th argument of Type1 corresponds to the J-th argument of Type2.
:- typeof +TypedTerm is +Type
Declares a type for the given term. TypedTerm is of the form Name(Type1,...,TypeN), where Type and TypeI are types. Type1,...,TypeN are the types of the arguments and Type is the type of the result.
:- type +TypeConstructor.
Declares a type. TypeConstructor is either of the form Name/Arity or of the form Name(A,B,...). It declares the existence of a type named Name which have Arity arguments.
:- type +Type is +TermConstructorList.
Combinaison of type and typeof. Type is of the form Name(A,B,...) and +TermConstructorList is alist of terms of the form Name(Type1,...,TypeN). The declared type is Type. The result type is Type.
:- untyped +SpecOrSpecList.
Avoid to type check the given terms. SpecOrSpecList is a functor specification of the form Name/Arity, or a list of such specifications. It causes TCLP to avoid to type check these terms.
5.3 TCLP meta declarations
:- tclp__include(+File)
Include TCLP declarations found in File.
:- user:args_location(+Location,?LocationList)
This predicate decompose the location of a term into the list of the locations of its subterms.
:- tclp__define_clause(+Phrase,+Location,+Heads,+Bodies,+Condition)
This will tell TCLP what the clauses look like. Phrase is the phrase to cut into bodies and heads. Location is the location of the phrase in the program source. Heads is a list of triplets Head-HLocation-Type, where Head is a head of the clause, HLocation is the location of Head in the program source (one can use user:args_location/2 to find it) and Type is the type expected for the head of the clause. Bodies is a list of pairs Body-BLocation, where Body is a body of the clause and BLocation is its location. Condition is a goal executed when recognizing clauses. E.g. (prolog directive ``:- Body''):
:- tclp__define_clause((:- Body), Location, [], [Body-BodyLocation], user:args_location(Location,[BodyLocation]))
:- tclp__define_clause(+Phrase,+Location,+Heads,+Bodies)
Same as tclp__define_clause(Phrase,Location,Heads,Bodies,true)
:- tclp__define_clause_op(+BinOp,+Type)
This predicate is a shortcut of tclp__define_clause/5 for defining binary clause operators such as ':-'/2. BinOp is the name of the operator and Type is the type expected for the head of the clause. E.g.
:- tclp__define_clause_op(':-',pred).
:- tclp__define_clause_op(+BinOp)
Same as tclp__define_clause_op(BinOp,pred)
:- tclp__executable(+Goal,+Condition)
Tells TCLP that the goal Goal is a TCLP declaration if the goal Condition succeeds. E.g. the op/3 directive:
:- tclp__executable(op(_,_,_),true).
:- tclp__executable(+Goal)
Same as tclp__executable(+Goal,true)
:- tclp__add_hook(+Goal,+Location,+Hook,+Condition)
Whenever TCLP encounters a TCLP declaration, it will handle it using a hook defined via this predicate. Goal is the TCLP declaration, Location is its location in the program source, Hook is the goal that will be executed by TCLP to handle the declaration and Condition is a goal that must succeed. E.g. the op/3 directive:
:- tclp__add_hook(op(Priority,Mode,Operators), _, op(Priority,Mode,Operators), true).
:- tclp__add_hook(+Goal,+Location,+Hook)
Same as tclp__add_hook(Goal,Location,Hook,true)
:- tclp__add_hook(+Goal,+Hook)
Same as tclp__add_hook(Goal,_,Hook)
5.4 Dialect specific declarations
:- tclp__load_prolog(+File)
Causes TCLP to consult File is in consult/1. This can be useful if you want to define complex treatments of some TCLP declarations.

Previous Up Next