Discussions related to Visual Prolog
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Suggestion for isErroneous object predicate for interface array2M

Unread post by Peter Muraya »

Hi,
I need to use a N by M matrix to manage a set of integers and have been thinking of objects created using the array2{integer}::newatomic constructor. To understand how this works I have done the following test, expecting to get a runtime error to the effect that position 0,0 is not set. Instead I got a 0, which is in the range of the integers I am managing.

Code: Select all

     run():-          X= array2M{integer}::newAtomic(2,2),          I = X:get(0,0), %I expected an exception at this point          stdio::write(I),          stdio::readChar()=_.
Is there a simple way of overriding the default 0 with a user-specified integer that is out of the expected range (without having to set all the values one by one using a loop)? If not can the newAtomic predicate be redefined to include this possibility, so that:-

Code: Select all

X= array2M{integer}::newAtomic(2,2, -1)
becomes a valid statement with the intended effect?

Better still, may I suggest the new predicate, say,

Code: Select all

 isErroneous:(positive X, positive Y) determ
for testing un-set cells of arrays.
Mutall Data Management Technical Support
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The initial (underlying) memory of an array is zeroed.

We can add a possibility initialization for the next version.

Setting to erroneous is not possible.

I suggest that you create a matrix class/interface which either inherits from the array2M or contains a fact variable of that type.

Not only will that make it possible for you to hold your own initialization code in this class, but it is also better practice to use an interface with your target abstraction rather than relying on exposing the full raw implementation details.
Regards Thomas Linder Puls
PDC
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Unread post by Peter Muraya »

Fine. I will follow the inheritance route.
Mutall Data Management Technical Support
Post Reply