Undeclared identifier & Undeclared fact

Discussions related to Visual Prolog
Loffy
Active Member
Posts: 42
Joined: 15 Aug 2019 11:32

Undeclared identifier & Undeclared fact

Unread post by Loffy » 15 Aug 2019 12:13

Dear Sir/Madam,

I am new to Visual Prolog 9, but experienced at PDC prolog syntax.

I am not yet competent with the object oriented features of Visual Prog 9.

I have created a new project with class facts defined in a database in TaskWindow.pro. These facts can be manipulated as I wish.

I have created a dialog within the TaskWindow pack called "Prime". This dialog is intended to change the status of a database fact called "user". On compilation I get two types of errors.

1. The first error is "error c229 : Undeclared identifier 'gui_native::setRect/1', the identifier is known as 'setRect/5->' in the class 'gui_native'" and is located in automatically generated code in the module "prime.pro"

2. The second error relates to the definition of the facts. When I try to find/assert/retract a "user" fact in "prime.pro" generated in a dialog I get the error "e283 Undeclared fact 'user/4' prime.pro TaskWindow\dialogs\".

I am fairly sure that the second error relates to a problem with my understanding of the definition of my database which I am trying to declare as "global facts" in the old world of PDC Prolog. At least at this stage, I want to be able to access facts within this database from any dialog I create.

Regards,

Loffy

User avatar
Thomas Linder Puls
VIP Member
Posts: 1622
Joined: 28 Feb 2000 0:01

Re: Undeclared identifier & Undeclared fact

Unread post by Thomas Linder Puls » 15 Aug 2019 14:58

Welcome back :wink:.

In future please only have one problem in each mail. Mail threads becomes very complex when they are about several topics .

The first problem sounds very strange. Please post this problem in a new mail, and include there relevant code in that mail. I will consider that problem closed in this mail thread.

The second problem is clearly related to a difference between PDC Prolog "global facts" and Visual Prolog "class facts".

PDC Prolog global facts was directly accessible from the entire program. Such facts does not exist in Visual Prolog.

In Visual Prolog facts (i.e. class fact as well as object facts) are only visible in the implementation where they are declared. So if you want to manipulate them "globally" you must do so through a predicate that is implemented in the relevant class.

I suggest that you don't have such application data in the task window class. Let us instead place it in a userInfo class. To add a user (from anywhere in the program) we will add a addUser predicate:

Code: Select all

class userInfo   predicates     addUser : (string UserName).   end class userInfo
The predicate will be implemented in the corresponding userInfo implementation where we also have the facts:

Code: Select all

implement userInfo   class facts     user_fact : (string UserName).   clauses     addUser(UserName) :-         assert(user_fact(UserName)).   end implement userInfo
Regards Thomas Linder Puls
PDC

Loffy
Active Member
Posts: 42
Joined: 15 Aug 2019 11:32

Re: Undeclared identifier & Undeclared fact

Unread post by Loffy » 16 Aug 2019 4:18

Thomas,

Thanks. I will try your suggestion later today.

I will send you a separate e-mail on the Undeclared identifier issue also later today. I have fixed the problem, but no doubt you will want to know what the problem was, and how it was fixed.

Regards,

Loffy

Loffy
Active Member
Posts: 42
Joined: 15 Aug 2019 11:32

Re: Undeclared fact

Unread post by Loffy » 20 Aug 2019 6:42

Thomas,

Thanks I believe I have done as you suggested, though something is still wrong, and probably stupidly wrong.

In taskwindow.pro I have two lines of code that load a text file containing facts, and one line of code that saves all facts when the application is closed. These 3 lines use the file::save/3 and file::consult/3 constructs. For example:
save("Data.txt", dba1, IsUnicodeFile),

With the old taskwindow.pro before I made your suggested changes these instructions worked.

Now I get the following error for all three lines:
Type Action Description Filename Path
e229 Undeclared identifier 'dba1' TaskWindow.pro TaskWindow\

In my new package called "database" I have the following construct:

Code: Select all

implement database     open core   class facts - dba1        user : (string UserID, string UserStatus, string UserName, string UserBlock) nondeterm.     pair : (string User1, string User2, string PairBlock, integer Count) nondeterm.   clauses     getDefaultNames(Namelist) :-         defaultnames(Namelist),         !.       getDefaultNames(_).       addUser(UserID, UserStatus, UserName, UserBlock) :-         assert(user(UserID, UserStatus, UserName, UserBlock)),         !.       addUser(_, _, _, _).       getUser(UserID, UserStatus, UserName, UserBlock) :-         user(UserID, UserStatus, UserName, UserBlock).       getUser(_, _, _, _).

User avatar
Thomas Linder Puls
VIP Member
Posts: 1622
Joined: 28 Feb 2000 0:01

Re: Undeclared identifier & Undeclared fact

Unread post by Thomas Linder Puls » 20 Aug 2019 8:02

Now that you have moved your facts to the database implementation, you can only access the fact database in that class. So you also have to move your consult and save code to that class.

Code: Select all

class database ... predicates     saveUsers : (string File).   end class database
With corresponding implementation:

Code: Select all

implement database ... clauses     saveUsers(File) :-         file::saveUtf8(File, dba1).   end implement database
And call this predicate from taskWindow

Code: Select all

implement taskWindow ... clauses     onSaveUsers( ...) :-         ...,         database::saveUsers(File),         ... end implement taskWindow
Your database implementation is the only one that deals directly with dba1.
Regards Thomas Linder Puls
PDC

Loffy
Active Member
Posts: 42
Joined: 15 Aug 2019 11:32

Re: Undeclared identifier & Undeclared fact

Unread post by Loffy » 20 Aug 2019 9:44

Thomas,

Thanks for your prompt response. I am now starting to understand classes better.

Regards,

Brian

Post Reply