What is New in Visual Prolog 7.0?

The programming language Visual Prolog has gone through a huge development in the latest years, and this will also continue in future. Most noticeable is the shift to object-orientation, and the introduction of parametric polymorphism.

The goals of the language update are to provide better means for creating and maintaining more complex programs for more complex surroundings.

Prolog Development Center extends Visual Prolog language thus the version 7.0 contains a lot of new language features.

You are also welcome to enjoy new Visual Prolog 7.0 features:

Development of the language caused some changes that might influence existing projects.

Visual Prolog online Help now includes a set of tutorials on Fundamental Prolog, Fundamental Visual Prolog, Integrated Development Environment, and various Visual Prolog features. Some tutorials are supplied with example projects that might be downloaded from Visual Prolog web site.

Polymorphism

Visual Prolog 7.0 introduces parametric polymorphism.  You can declare parameterized domains.  For example:

domains
    binTree{Elem} =
        node(binTree{Elem} Left, Elem Node, binTree{Elem} Right);
        leaf().

Such a polymorphic domain replaces a complete range of (non-polymorphic) domains:

domains
    bintree_integer =
        node(bintree_integer Left, integer Node, bintree_integer Right);
        leaf().
domains
    bintree_string =
        node(bintree_string Left, string Node, bintree_string Right);
        leaf().
...

Moreover, polymorphic predicates can manipulate the polymorphic data structures.  This predicate will insert a node in an ordered binary tree:

predicates
    insert : (Elem NewNode, binTree{Elem} Tree) -> binTree{Elem} NewTree.
clauses
    insert(NewNode, leaf()) = node(leaf(), NewNode, leaf()).
    insert(NewNode, node(Left, Node, Right)) = NewTree :-
        NewNode <= Node,
        !,
        NewTree = node(insert(NewNode, Left), Node, Right).
    insert(NewNode, node(Left, Node, Right)) = NewTree :-
        NewTree = node(Left, Node, insert(NewNode, Right)).

This single predicate can insert elements in any kind of binTree's:

clauses
    ppp() :- 
        StrTree1 = insert("AAA", leaf()),
        StrTree2 = intert("BBB", StrTree1),
        IntTree1 = insert(17, leaf()),
        IntTree2 = insert(23, IntTree1),
        ...

Polymorphism guarantees type safety, meaning that you cannot insert an integer into a string tree:

clauses
    ppp() :-
        StrTree1 = insert("AAA", leaf()),
        SomeTree2 = insert(23, StrTree1),  % type error
        ...

Such errors are detected at compile time.

In object-oriented programming languages, it is quite common to create data structures like the binary tree using object as an element type:

domains
    bintree_object =
        node(bintree_object Left, object Node, bintree_object Right);
        leaf().

Since any object can be converted to object, you can insert any object in such a binary tree.  However, this has certain drawbacks (all stemming from the same cause):

  • If you have a tree of "windows", you can insert a "person" object in the tree (because they are all objects)
  • When you extract an element from the tree it will have the object type and, therefore, you will have to convert it back to its original type.

These drawbacks do not exist for polymorphic domains:  all the elements in the tree are guarantied to have the same type, and, when you retrieve an element from the tree, it will have exactly that type.  (This type can, of course, be object if you like).
For more details see "Visual Prolog Objects and Polymorphism"

PFC Classes for List Handling

List domains are polymorphic domains.  Therefore, it is possible to "reuse" list predicates for any kinds of lists:

predicates
    isMember : (Elem Elem, Elem* List) determ.
clauses
    isMember(Elem, [Head|Tail]) :-
        Elem = Head
        or isMember(Elem, Tail).

This predicate can be used on integer lists:

isMember(17, [23, 45, 32, 17, 58])

It can also be used on string lists:

isMember("aaa", ["asd", "asd", "asd"])

But you cannot use it like this:

isMember("aaa", [23, 45, 32, 17, 58]) % type error

And lists like this does not exist:

L = [23, "aaa", 32, 17, 58] % type error

"if-then-else" construction

if-then-else is introduced as a language construction:

clauses
    p(X) = Y :-
        if X = 1 then
            Z = 3
        else
            Z = 7
        end if,
        Y = 2*Z.

If then else can also be used without the else part:

clauses
    p(X) = Y :-
        if trace = true() then
            writef("Started p(%)\n", X)
        end if,
        ...

Deeply Nested "or"

In Visual Prolog 7.0, it will be possible to nest "or" deeply in clauses.

clauses
    p(X) = Y :-
        (X = 1, !, Z = 3 or Z = 7), Y = 2*Z.

Here we have used the keyword "or", but you can also use semi-colon ";".

We recommend a careful usage of "or"; it is mainly intended for usage in if-then-else constructions:

clauses
    p(X) :-
        if X = 1 or X > 17 then
            ...
        end if.

Foreach

New language construction foreach:

…,
foreach p_nd(X) do
   write(X), nl()
end foreach,
…

The foreach construction is intended as a replacement for fail loops:

…,
p_nd(X)
   write(X), nl()
fail.

However, the "foreach" construction succeeds, when the iteration is completed.  So computation will continue right after the "foreach" construction (rather than in the next clause).

…,
foreach p_nd(X) do
   write(X), nl()
end foreach,
write("I will continue here"),
...

"foreach" constructions can also be nested properly:

…,
foreach p_nd(X) do
   foreach q_nd(X, Q) do
       writef("Q = %, ", Q)
   end foreach,
   foreach r_nd(X, R) do
       writef("R = %, ", R)
   end foreach,
   writef("\nThat was for X = %\n", X)
end foreach 
...

List Comprehension

Visual Prolog 7.0 introduces a new syntax and improved functionality as a supplement to findall/3.

..., List = [ A || p_nd(A) ], ...

The line above corresponds to this:

..., findall(A, p_nd(A), List), ...

The new construction is a value, and can be used as such:

..., ppp( [ A || p_nd(A) ] ), ...

The functionality has been improved so that you can calculate the values to collect:

..., List = [ pair(A, math::sin(A)) || p_nd(A)  ], ...

You can also have more calls in the "body":

..., List = [ R  || p_nd(A), S = math::sin(A), R = pair(A, S)  ], ...

Stronger Type System with Regards to Subtyping

Domain declarations like this:

domains
    myType = someType.

will define a sub-type (unless someType is a compound domain or a predicate domain) rather than a synonym type.

Values of type "myType" can automatically be used as type "someType", but a value of type "someType" will have to be explicitly converted to type "myType".

The purpose of this is to increase the safety of your programs.  Consider this little setup:

domains
    styleFlag = integer.
    color = integer.
predicates
    createWindow : (..., styleFlag Style, color Color).

"..." is meant as an abbreviation of a number of other arguments.  If "styleFlag" is synonym to "integer", and "color" is also synonym to "integer", then "styleFlag" and "color" are also synonym to each other.  Therefore a bogus call like this:

clauses
    ppp(...) :-
        Color = getColor(),
        StyleFlag = getStyleFlag(),
        createWindow(..., Color, StyleFlag). % bogus

is legal.  This is no longer the case: a "color" cannot be used as a "styleFlag" (and vice versa), unless you explicitly convert it.

Stronger Treatment of Numerical Types

One very noticeable consequence of this change is that integer and unsigned are kept much stricter apart from each other.  If you have an integer but need an unsigned, you will have to convert it explicitly.

Faster Compiler

Visual Prolog 7 Compiler is faster than Visual Prolog 6 Compiler, the exact rate varies from file to file.

Version Control

Version Control is the convenient way to represent version information in your project. A newly created IDE project contains About dialog with version controls.

redBlackTree PFC package and list PFC package

A fast way to access to a collection of data is very demanded. Visual Prolog 7 supplies redBlackTree package to maintain such collections.

The possibility of the declaration of a general list domain allows to use the general PFC package to handle lists.

Variable Support in IDE

IDE Variables can be used in Project Settings Include directories and in Tools Commands, thus it becomes more flexible and convenient to adjust IDE and Project settings to work on big projects.

COM Wrapper Generates struct Alignment

When COM structures are used in Visual Prolog, they should have exactly the same binary representation as the ones in COM itself. Visual Prolog 7.0 contains many enhancements in COM generation and one of the main improvements is the generation of extra dummy fields to take alignment in account.

Grid Control as a Demo Example

Object Oriented Grid Control was asked at VIP ALC Conference, and it is included in demo examples, which are available by running setupExamples for Visual Prolog 7.0 Commercial Edition.

Nice IDE Small Improvements

IDE has many nice improvements, for example you can see the percentage rate of build progress, easier edit control attributes in Dialog Editor and many more.

New Accelerator Key Bindings

Beginning with Visual Prolog 7.0 some key binding have been changed to comply with Microsoft standards.

Backwards Compatibility Issues

  1. Reference domains are not supported.
    Read "How To Erase Reference Domains from a Project".

  2. The following new keywords have been introduced:

 if, then, else, foreach, do.

This means that they can no longer be used as identifiers (Visual Prolog 6.3 gave a warning about this).
 

Current Build of Visual Prolog 7.0

The current Build of Visual Prolog 7.0 is the Build 7004.

See Also

Visual Prolog 7.0 Upgrade Notes

Visual Prolog 7.0 Build 7004

 

Home | Company | News | Products Downloads | Shop | Support | Visual Prolog Features | Visual Prolog Compiler | FAQ | Tutorials | Examples | Knowledge Base | Discussion Forum | wiki | Site Map
 

Prolog Development Center A/S - H.J. Holst Vej 3-5C - 2605 Broendby, Denmark - Tel +45 3636 0000 - Fax +45 3636 0001 - sales@visual-prolog.com