Visual Prolog 7 TutorialsVisual Prolog 7 for Visual Prolog 5 Users written by Yuri Ilyin Last updated: 15-11-2007 This is not really a tutorial, but a quick guide to the differences between Visual Prolog 7 and Visual Prolog 5. The focus is on Visual Prolog 5 features that have been changed, rather than new features. DotsAll declarations (i.e. constants, domains, predicates and facts) are terminated by a dot (i.e. "."). PredicatesThe syntax of predicate declarations has changed in several respects. This example illustrates most of the changes:predicates ppp : (integer Input) procedure (i). qqq : (integer Input) -> integer Output procedure (i).
In a predicate declaration the omitted predicate flow means all arguments input. Special keyword anyflow can be used in local predicate declarations to specify any flow. Predicate DomainsThe syntax of predicate domain declarations has been changed similarly: domains pppDom = (integer Input) procedure (i). qqqDom = (integer Input) -> integer Output procedure (i). Reference DomainsVisual Prolog does not support reference domains since Visual Prolog 7.0 version. See: How To Eliminate Reference Domains from a Project. Function ClausesThe syntax of function clauses has been changed so that the return value is placed after an equal sign in the clause head: clauses qqq(X) = 1 :- X < 3, !. qqq(X) = X. ConstantsConstants are no longer macros, but must be values of a certain type. constants myList : integer_list = [14, 56, -3]. The type can be omitted for number, character and string constants. FactsThe declarations are similar to predicate declarations: facts - myFactDB fact1 : (integer Input) nondeterm.
Fact VariablesFact variables is a new notion. They are declared in facts sections: facts myFactVariable : integer_list := [14, 56, -3]. Visual Prolog 5 users can consider this to be equivalent to the following single fact with accompanying initialization. facts myFact : (integer_list Value) single. clauses myFact([14, 56, -3]). Fact variables are used like variables, as it is known from imperative languages: clauses p() :- myFactVariable := [14, 56, -3], q(myFactVariable). Visual Prolog 5 users can consider this to be equivalent to the following code: clauses p() :- assert(myFact( [14, 56, -3])), myFact(Value), q(Value). Nested Expressions and FunctionsExpressions and functions can be nested practically everywhere: clauses factorial(0) = 1 :- !. factorial(N) = N * factorial(N-1). Above you can see that the return value in the second clause is an expression. This expression contains a function call, and the argument to this function is also an expression. Compiler DirectivesCompiler directives start with #. For example: #include @"packageAaa\packageAaa.ph"
StringsThe @ symbol before a string literal means that an escape sequence is not used, i.e. @"\n" represents 2 symbols \ and n. The \ symbol can be used only before n, t, r, \. Therefore "\x" does not mean "x" anymore. Characters like '\013' should be written in Unicode (and hex) format '\u000D'. Conditional CompilationConditional compilation can only be applied to sections in Visual Prolog 7.For example: #if a::myconst = 1 #then clauses p(0) = 1. #endif This Visual Prolog 5 code clauses p(X):- ifdef debug_mode write("X",X), endif q(X). corresponds to the following Visual Prolog 7 code:
class predicates writeX : (integer X). #if globalConstants::debug_mode = 1 #then clauses writeX(X):- stdIO::write("X=",X). #else clauses writeX(_). #endif clauses p(X):- writeX(X), q(X). Input, Output and Domains "file", "db_selector"The file domain is placed into the fileSelector class. The db_selector domain is placed into the chainDBSelector class. The files pfc\5xVIP\fileSelector.cl and pfc\ChainDB\chainDBSelector.cl should be copied to a project directory (into the appropriate sub-directory) before they are modified. These domains are introduced only for backwards compatibility. The new style is to use objects instead. IO handling is based on streams. Stream predicates use anonymous argument type and ellipsis. Ellipsis and Anonymous Argument TypeIf a number of arguments can vary, then ellipsis is used. Ellipsis is a special notation that means "zero or more arguments of any type". The syntax is: class predicates p : (...). clauses p(...):- stdio::write(...). If a type of an argument is not known at compile time, anonymous argument type is used. The syntax is: class predicates
setProperty : (_).
Objects and ClassesDifferences in Visual Prolog 5 and Visual Prolog 7 object models are described in the Tutorial 3. Library SupportThe Library support page describes Visual Prolog 7 equivalents for Visual Prolog 5 names. Libraries are in general new, written according to object concept. There is a special library 5xVip including sub-folders. The library is intended for migrating Visual Prolog 5 code. New programs should not use 5xVip library. |
|
|