Everybody who has ever tried to write a large program in any non-typed computer language will surely have encountered a lot of problems ...
We decided to provide an optional type checking mechanism: The definition of every predicate must be preceded by a declaration. Some programmers will think of this as a major restriction. We think, that this is the only way to create large programs that really run.
In PROLOG, there are various data types (Stating that BAP is not typed means that at any place any type of data may appear. It does not mean that the data has no type!). The standard types are:
By the use of the DOMAINS
DOMAINS sex :- male; female. age :- integer. name :- string. namelist:- name*. % this means 'list of names' person :- person(name,sex,age).Example Usage:
PREDICATE is_old_man(person). is_old_man(person(_,male,Age)) :- Age > 70.The result of the domain declaration is that some new predicates are created that look similar like:
PREDICATE sex(void). sex(Var) :- free(Var),!. sex(Var) :- Var = male,!. sex(Var) :- Var = female,!. PREDICATE age(void). age(Var):- free(Var),!. age(Var):- integer(Var),!. PREDICATE name(void). name(Var):- free(Var),!. name(Var):- string(Var),!. PREDICATE namelist(void). namelist(Var) :- free(Var),!. namelist() :-!. namelist([Name|Rest]):- name(Name), namelist(Rest),!. PREDICATE person(void). person(Var) :- free(Var),!. person(person(Name,Sex,Age)):- name(Name), sex(Sex), age(Age),!.
This mechanism gives you a chance to avoid declaring erroneously a person as being 'male' years old.