Domain Declaration with different type..??

Discussions related to Visual Prolog
User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Domain Declaration with different type..??

Unread post by George » 18 Oct 2011 5:17

Hi..

I have got few compilation error when i do domain declaration like below code.. kindly clarify it..

Code: Select all

domains     myType = integer;real ; string.  %Does it possible to declare domain like this  ??? predicates     onFileNew : window::menuItemListener.     divByZero : (myType, myType). clauses     onFileNew(_Source, _MenuTag):-         X = 10,         Y = 0,         divByZero(X, Y).             divByZero(X, Y):-         try             Z=  X / Y         catch TraceId do             vpiCommonDialogs::note("div by zero exception")          end try.    

Exception 1:
TaskWindow\TaskWindow.pro(60,13) error c504: The expression has type '::integer', which is incompatible with the type 'taskWindow::myType'
Exception 2:
TaskWindow\TaskWindow.pro(66,19) error c504: The expression has type '(::real, ::real) -> ::real procedure (i,i)', which is incompatible with the type '(taskWindow::myType, A$) -> R$ procedure (i,i)'
It is working when i define integer alone in the domain section...

kindly help me to understand why this exception happened and how to fix it...??


Thanks,
George Ananth. S

User avatar
Tonton Luc
VIP Member
Posts: 501
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 18 Oct 2011 6:53

Hi,
Maybe try this (instead domains myType) :

Code: Select all

predicates     divByZero : (integer, integer).     divByZero : (real, real).     divByZero : (string, string).

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Unread post by George » 18 Oct 2011 7:28

Thanks Tonton Luc :!:

It works fine now.

Could you please tell why it doesn't work for my earlier code..??

Thanks,
George Ananth. S

User avatar
Tonton Luc
VIP Member
Posts: 501
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 18 Oct 2011 10:39

Hi,
Because I suppose it's not correct to declare some domains like this :
domains
myType = integer;real ; string.
I never see it in any VP7 samples.

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Unread post by George » 18 Oct 2011 10:45

I never see it in any VP7 samples.
Ok..

Could you please let me know where i can find the samples of VP7 which will be more helpful to lean coding with efficient way..??

Tell me if you have any exception handling samples aslo...


Thanks,
George Ananth. S

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 18 Oct 2011 12:46

Code: Select all

domains     myType = integer;real ; string.  %Does it possible to declare domain like this  ???
Hi,
No. You would have to do this:

Code: Select all

domains     myType = i(integer);r(real); s(string).
regards
Steve

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Re:

Unread post by George » 18 Oct 2011 13:34

Steve Lympany wrote:

Code: Select all

domains     myType = integer;real ; string.  %Does it possible to declare domain like this  ???
Hi,
No. You would have to do this:

Code: Select all

domains     myType = i(integer);r(real); s(string).
regards
Steve
Thanks Steve..

Declaration is works fine...

but after finish implementation by using the myType domain, I was getting the error message,

Please find the below error message,
TaskWindow\TaskWindow.pro(82,13) error c504: The expression has type '::integer', which is incompatible with the type 'taskWindow::myType'
Code I tried:

Code: Select all

domains     myType = i(integer); r(real); s(string). predicates   divByZero : (myType, myType).   onFileNew : window::menuItemListener. clauses     onFileNew(Source, _MenuTag):-         X = 10,         Y = 6,         divByZero(X, Y),         A = 50,         B = 60.34,         divByZero(A, B),         C = "40",         D = "60",         divByZero(C, D),         !.    onFileNew(_, _):- !. divByZero(X, Y):-     vpiCommonDialogs::note(string::format("% - %", X, Y)).  
Could you please clarify why this error getting..??

Thanks,
George Ananth. S

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 18 Oct 2011 14:57

Hi,
Yes - the clue is in the error message :wink:. You are calling it with an integer and not mytype. So

divByZero(5,6)

should be:

divByZero(i(5),i(6))
divByZero(r(5.2),r(6.7))

I am not sure what you are doing dividing strings :?:

Code: Select all

    divByZero(_X, i(0)):-             vpiCommonDialogs::note("div by zero exception")     divByZero(i(X), i(Y)):-              Z=  X / Y     divByZero(_X, r(0)):-             vpiCommonDialogs::note("div by zero exception")     divByZero(r(X), r(Y)):-              Z=  X / Y
cheers
Steve

User avatar
George
VIP Member
Posts: 313
Joined: 19 Sep 2011 8:54

Re:

Unread post by George » 18 Oct 2011 15:10

Steve Lympany wrote:Hi,
Yes - the clue is in the error message :wink:. You are calling it with an integer and not mytype. So

divByZero(5,6)

should be:

divByZero(i(5),i(6))
divByZero(r(5.2),r(6.7))

I am not sure what you are doing dividing strings :?:

Code: Select all

    divByZero(_X, i(0)):-             vpiCommonDialogs::note("div by zero exception")     divByZero(i(X), i(Y)):-              Z=  X / Y     divByZero(_X, r(0)):-             vpiCommonDialogs::note("div by zero exception")     divByZero(r(X), r(Y)):-              Z=  X / Y
cheers
Steve
Thank you so much Steve :!:

Able to do it now with your solution...
I am not sure what you are doing dividing strings :?:
I'm not doing anything with that string Steve.. I just verified how to do method overloading by giving different input... Thanks again.. This logic i ll be using for my project work..

And Steve if you don't mind, could you please give me some idea for runtime exception handling.. I couldn't find any special predicate to get the exact error message as well as class name and predicate name..

whatever i find the predicate, that will provide the lot of information.. If you have any idea please share with me..

Thanks,
George Ananth. S

User avatar
Tonton Luc
VIP Member
Posts: 501
Joined: 16 Oct 2001 23:01

Re:

Unread post by Tonton Luc » 18 Oct 2011 15:56

Ananth wrote:Could you please let me know where i can find the samples of VP7
:idea: From VP7 IDE, use menu Help/Install Examples...

Post Reply