Difference between revisions of "Visual Prolog 7.2 New Features"

From wiki.visual-prolog.com

(New page: =New Features in Visual Prolog 7.2= Visual Prolog 7.2 brings many new features and improvements, this paper will describe the most significant changes. ==''' 1 Language Features '''== ...)
(No difference)

Revision as of 16:50, 18 September 2008

New Features in Visual Prolog 7.2

Visual Prolog 7.2 brings many new features and improvements, this paper will describe the most significant changes.

1 Language Features

Visual Prolog 7.2 brings several language improvements. This section gives a brief overview of some of them.

1.1 Anonymous predicates

Anonymous predicates are the Prolog counterparts to anonymous functions as known in functional programming languages. Anonymous predicates are described in details in the paper Anonymous Predicates, and presented in a separate session at the VIP-ALC 2008 conference.

1.2 64 bit numbers

integer64 and unsigned64 are two new built-in types, that replace the PFC domains core::intege r64 and core::unsigned64. The new domains are like integer and unsigned expect that they have a 64-bit representation. All arithmetic operations (except the power operation) are supported for the types. They are written, read, saved and consulted in normal number format only with much larger range than 32-bit numbers. PFC has been updated to use integer64 and unsigned64 instead of core::integer64 and core::unsigned64. So now (as example) file positions are unsigned64. The same is the case with gmtTimeValue, localTimeValue and timeIntervalValue.

1.3 Namespaces

Interfaces and classes can be put into name-spaces (like pfc\pie). This allows the same interface/class name to be declared/defined in several name spaces in the same program. So now it is possible (as example) to have a class called file in the namespace documentManager even though there is also a class named file in PFC. It is planned (but not effectuated at the time of writing) to put PFC classes in namespaces pfc, pfc\vip5x and pfc\gui. Also the new pie packages (described below) are in the name space pfc\pie.

1.4 binaryNonAtomic domain

A new built-in domain binaryNonAtomic is introduced to distinguish binaries may contain pointers and should therefore be scanned by the garbage collector. The ordinary binary domain is no longer scanned for pointers.

1.5 real32

A domain real32 is introduced to ease the integration with foreign API's that sometimes uses such short reals. It is not intended for use in "normal" code.

2 Compiler

The compiler is (obviously) updated to deal with the new language features. But it has also been improved in several other respects.

2.1 Unreachable code detection

The ability to detect unreachable code has been improved vastly, both when it comes to detecting unused predicates and facts and when it comes to code inside clauses which cannot be reached. Unreachable code will cause warnings.

2.2 Superfluous test detection

The compiler will also give warnings about tests, which are trivially fulfilled due to the type of the involved variables. Consider this code for example:

clauses
     ppp(X) :- 
         Y = X - 23, 
         Y >= ,  
        qqq(Y).

where qqq is declared like this:

predicates
      qqq : (positive V).

The code above might seem reasonable, we only want to call qqq if Y is indeed greater than or equal to zero.

The only problem is Y is always greater than zero, because Y has the type positive, which only contains numbers that are greater than or equal to zero.

If the calculation X 23 gives a negative number an out-of-range exception will be raised (before reaching the test). >So this new warning can help the programmer detect places where it seems that testing ensures validity of the code, while in reality the test will never fail because an exception will be raised instead. The code above can be corrected using this code: clauses ppp(X) :- Y = tryConvert(positive, X - 23), qqq(Y). If X - 23 gives a negative number, the tryConvert will fail.

2.3 Smaller code

The size of the generated code has become smaller, especially for predicates with many clauses that match different patterns of input.

2.4 Less stack usage

Likewise, the stack size has been reduced (dramatically in some cases).

3 IDE

Many bugs and inconveniences have been solved in the IDE. Just like numerous smaller and larger improvements has been made. This section describes some of the major improvements.

3.1 Build speed

The build system has been changed such that it can utilize multi-core processors by compiling several packages in parallel. On a quad-core processor this typically gives a factor 4 (sometimes more) when many packages needs to be compiled.

As a drawback the computer is not very responsive while building, because all the cores are kept quite busy.

As of this writing, we are also working on letting the compiler itself compile several packages in a single invocation and thus skip many compiler phases for files that are included in several packages.

This feature has given a factor 4 when rebuilding a very large project.

The two features have not yet been tested together, so it is too early to say something about the combined improvement.

3.2 IntelliSence

Browse information (i.e. information about the source code fed from the compiler back to the IDE) is now utilized to provide IntelliSense: When you edit source code the IDE shows possible/sensible completion of the word you are typing. You can then select the completion in the list using mouse, arrow keys and TAB; the IDE will complete the word with your choice. The IDE will also show tool tip windows showing the declaration of the predicate you are about to write arguments for. That way you can see which arguments the predicate takes without changing context.

3.3 Window Navigation Dialog

The order, in which Ctrl-TAB shifts between IDE windows, has been changed to visit most-recently-visited windows first.

Furthermore, Ctrl-TAB also brings up a navigation dialog listing all the open windows. The dialog stays up as long as Ctrl-key is pressed. In this dialog you can see the windows in the order they will be shifted to, but you can also choose a window directly using the mouse or the arrow keys. If you press letters the list will be filtered to

windows starting with the letters you have pressed.

3.4 Grouping editor windows

Editor windows can be grouped together to look and behave like a single window. This has the advantage that you can arrange windows in a fixed layout inside the IDE. The IDE will remember two different layouts, one for "normal" mode and one for debug mode. Typically, you want large editor windows in "normal" mode, but smaller editors in debug mode to give more room for the variables window, etc.

3.5 Resources view in project tree

When selecting a resource (e.g. a dialog or a bitmap) in the project tree, the right pane will show a preview of the resource.

3.6 Zooming

Pressing the Ctrl and using the mouse wheel the IDE will increase/decrease font size in various windows creating a zoom effect. Zooming is also bound to Ctrl-+, Ctrl--, and Ctrl-0 reset to 100%.

3.7 Un-/commenting blocks

The editor has new commands for commenting and un-commenting a block of code with %-chars. The commands are bound to Ctrl-Alt-% and Ctrl-Alt-Shift-%. (It would be more correct to state the keys as Ctrl-Alt-5 and Ctrl-Alt-Shift-5, but it seems simpler to remember the %-key).

4 PFC

PFC has mainly been consolidated, updated to 64-bit numbers and things like that. But there are also some new things.

4.1 PIE

The engine of PIE (Prolog Interpreter Engine) is now added to PFC and will therefore be supported as a tool in future. The most important feature is that you can easily hook-in predicates from you own application. Subsequently, the PIE programs can manipulate your application. So PIE is very useful as a scripting engine in applications. Besides this, the efficiency has been improved and PIE now supports functions and real numbers.

4.2 progressBarControl

A progressBarControl binds to the win32 common control progress bar. It is the intension to add additional win32 common controls, but to deal more easily with them certain inner parts of PFC GUI will have to be revised first.

4.3 postAction

A new predicate postAction on the window class, makes it possible to post an action to any window. The action will be packed in a user message and when the user message is handled the action is executed. Together with anonymous predicates this makes any other use of user messages superfluous.

4.4 popupWindow

A new class popupWindow makes it easier to create popup windows like tooltips. Most importantly popup windows must have the screen as parent so that they can be drawn outside their logical owner and on top of other windows.

4.5 radixTree

A radix tree is a map from pointer to any type. Its main advantage (over for example red-black-trees) is that supports very efficient merge of several maps. The disadvantage is that the keys are pointer values, so the trees can only be used on things with unique pointers (like object and symbol).

4.6 uxTheme native bindings

Native bindings to uxTheme make it possible to experiment with creating theme aware controls. Theme aware controls are not drawn using lines, circles, rectangles, etc. Instead they are drawn using theme elements. Theme elements are logical graphical entities like divider line, button surface, button outline, drop-down mark, etc. You combine/draw such logical elements into your control, and when the theme changes your control will also change appearance. If you have chosen the elements wisely your control will also blend-in with other themes.

4.7 getFactChainLength_nd

A new predicate getFactChainLength_nd (in the profileMemory class) returns the number of facts in each class fact chain in the entire program. It is intended to help tracking down problems with class facts that are not retracted when they should and therefore eats memory by keeping data alive that should have been dead.

4.8 weakPointer

Weak pointers are "pointers" that the garbage collector does not see as pointers, so if there are only weak pointers to a piece of memory the garbage collector will recycle that piece of memory. As a consequence, a weak pointer cannot always be dereferenced, sometimes the target as been recycled. Dereferencing of a weak pointer it therefore done using a determ predicate.

So in short a weak pointer is a pointer that will not keep memory alive.