How to convert from list to be different name

Discussions related to Visual Prolog
danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

How to convert from list to be different name

Unread post by danepa » 27 Oct 2011 14:50

Code: Select all

class facts - maxDB     max : (string Max).       clauses      loadMax():-           try               FileName = concat(directory::getCurrentDirectory(), "\\max.txt"),               consult(FileName, maxDB)           catch TraceId do               exceptionDumper(TraceId),               stdIO::writef("\n\n")           end try.   clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         loadMax(),         getAllMax(MaxList),         penyakit_ctl:addList(MaxList).   getAllMax(MaxList) :-         findAll(Max, max(Max), MaxList),         MaxList <> [], !.
how to convert from MaxList to be input1, input2, input3 in a series?

here is a sample from the database max.txt :

Code: Select all

clauses max("\"0.2\""). max("\"1\""). max("\"0\""). max("\"0.5\"").
Daniel

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

Unread post by Tonton Luc » 27 Oct 2011 15:54

Hi,

I suppose you need to convert string to real...
:idea:

Code: Select all

facts mem_max_list:real_list:=erroneous.   predicates getAllMax(real_list) procedure(o). clauses getAllMax(MaxList_real) :-     findAll(Max, max(Max), MaxList),     mem_max_list := [],     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         X = list::nth(Cpt,MaxList),         mem_max_list := list::append(mem_max_list,[X])     end foreach,     MaxList_real = mem_max_list.

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 28 Oct 2011 1:40

Tonton Luc wrote:Hi,

I suppose you need to convert string to real...
:idea:

Code: Select all

facts mem_max_list:real_list:=erroneous.   predicates getAllMax(real_list) procedure(o). clauses getAllMax(MaxList_real) :-     findAll(Max, max(Max), MaxList),     mem_max_list := [],     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         X = list::nth(Cpt,MaxList),         mem_max_list := list::append(mem_max_list,[X])     end foreach,     MaxList_real = mem_max_list.
It will save in MaxList_real right? but, how can i save it into input1, input2, etc? thanks.

Code: Select all

clauses max("\"0.2\""). %it will be input1 max("\"1\""). %it will be input2 max("\"0\""). %it will be input3 max("\"0.5\""). %it will be input4
Daniel

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

Unread post by George » 28 Oct 2011 7:53

Dear danepa,

:idea:


Do onething.. After get the real data in one list.. just iterate that list and assign the value to the corresponding fact variables(input1, input2 etc)..

I think, you need to hard code like following,

Code: Select all

clauses setValueToInputVariables(MaxList, 0),  %Pass input here.. .. .. . clauses setValueToInputVariables([], _Temp):- !. setValueToInputVariables([MaxHead|MaxTail], Temp):-   Temp1 = Temp + 1,   if Temp1 = 1 then    input1 := MaxHead   elseif Temp1 = 2 then    input2 := MaxHead   elseif Temp1 = 3 then    input3 := MaxHead   elseif Temp1 = 4 then    input4 := MaxHead   elseif Temp1 = 5 then    input5 := MaxHead   elseif Temp1 = 6 then    input6 := MaxHead   ..   ..   ..   else     inputn := MaxHead   end if,   setValueToInputVariable(MaxTail, Temp1).  
Try this.. you will get the output..

This u can do if your input is fixed.. like it will not vary for different times..
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282

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

Unread post by Tonton Luc » 28 Oct 2011 8:26

:idea:

Code: Select all

facts mem_max_list:real_list:=[input1,input2,input3,etc...].   predicates getAllMax(). clauses getAllMax() :-     findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)     end foreach.

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

Re:

Unread post by George » 28 Oct 2011 9:08

Tonton Luc wrote::idea:

Code: Select all

facts mem_max_list:real_list:=[input1,input2,input3,etc...].   predicates getAllMax(). clauses getAllMax() :-     findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)     end foreach.
Can you plz tell me.. Does it possible the fact variable can be hold in a list.. ??

ex:

Code: Select all

domains real_list = real*. facts input1 : real := 0.0. %fact variable input2 : real := 0.0. %fact variable input3 : real := 0.0. %fact variable input4 : real := 0.0. %fact variable input5 : real := 0.0. %fact variable mem_max_list:real_list := [input1,input2,input3,input4].  %Does it hold the value[0.0, 0.0, 0.0, 0.0] or variable name([input1,input2,input3,input4])..
If it's(mem_max_list) hold the variable name then, we can assign the value by iterating like your code.. If it's hold value then it will be another list which will hold the value.. right..? but not get assigned..??

How come it will get assigned to input1 to input4...??


Kindly clarify..
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282

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

Unread post by Thomas Linder Puls » 28 Oct 2011 9:41

To Ananth & Tonton

No, that is not possible. The list will contain the values from the fact variables, not the fact variables themselves.

To danepa

The good people above are trying to assist you by providing inventive suggestions. But the real answer is: don't.

Your problem is wrong because you misuse fact databases. Any solution to your problem will be equally wrong.

If you want a fact database where each fact represent different things then the database should reflect that:

Code: Select all

clauses observation("aplikasiPasien", 17.3). observation("sakitGigi", 0.231). ...
How to work with such a fact database, etc. will be much clearer if you first follow some of the tutorials. So once again, I will urge you to follow the tutorials before trying to solve your own problem.
Regards Thomas Linder Puls
PDC

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

Unread post by George » 28 Oct 2011 15:38

Thanks for clarified my doubt Mr. Thomas Linder Puls :!:
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 29 Oct 2011 3:08

Tonton Luc wrote::idea:

Code: Select all

facts mem_max_list:real_list:=[input1,input2,input3,etc...].   predicates getAllMax(). clauses getAllMax() :-     findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)     end foreach.

Code: Select all

facts    mem_max_list:real_list:=[ input1,  input2,  input3,  input4,  input5 , input6,  input7,  input8,  input9,  input10,  input11,  input12,  input13,  input14,  input15,  input16].   clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         loadMax(),         loadUserOnline(),         getAllMax(MaxList).   getAllMax(MaxList) :-         findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)     end foreach. getAllMax([]) :-         vpiCommonDialogs::error("database is empty").
error c161: Syntax error: 'fact variable or property name' is expected

I don't understand why it is an error. Can u tell me?
Daniel

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 29 Oct 2011 12:59

again, a syntax error.

You are trying to assign the output of a function to a function. (note the red highlight)

list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)

If you are trying to compare the nth elements of the two lists you need the =, however, that will not work either because the predicate calls/clauses within a foreach loop can not fail. you should call out to another predicate (preferably that is a procedure) that will do the compare, always 'succeed' and return a value, then you can act on the returned value (elements are equal or not). but rememebr, all clauses inthe foreach loop must not "fail" or you will receive another compiler error.

you need to 're-think' what it is you are trying to do (and how) and watch your code structure and syntax.
AI Rules!
P.

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 31 Oct 2011 4:29

Paul Cerkez wrote:again, a syntax error.

You are trying to assign the output of a function to a function. (note the red highlight)

list::nth(Cpt,mem_max_list) := list::nth(Cpt,MaxList)

If you are trying to compare the nth elements of the two lists you need the =, however, that will not work either because the predicate calls/clauses within a foreach loop can not fail. you should call out to another predicate (preferably that is a procedure) that will do the compare, always 'succeed' and return a value, then you can act on the returned value (elements are equal or not). but rememebr, all clauses inthe foreach loop must not "fail" or you will receive another compiler error.

you need to 're-think' what it is you are trying to do (and how) and watch your code structure and syntax.
i've already edit it...

Code: Select all

facts     input1 : real := 0.0. %fact variable     input2 : real := 0.0. %fact variable     input3 : real := 0.0. %fact variable     input4 : real := 0.0. %fact variable     input5 : real := 0.0. %fact variable     input6 : real := 0.0. %fact variable     input7 : real := 0.0. %fact variable     input8 : real := 0.0. %fact variable     input9 : real := 0.0. %fact variable     input10 : real := 0.0. %fact variable     input11 : real := 0.0. %fact variable     input12 : real := 0.0. %fact variable     input13 : real := 0.0. %fact variable     input14 : real := 0.0. %fact variable     input15 : real := 0.0. %fact variable     input16 : real := 0.0. %fact variable    mem_max_list:real_list:=[ input1,  input2,  input3,  input4,  input5 , input6,  input7,  input8,  input9,  input10,  input11,  input12,  input13,  input14,  input15,  input16].   clauses      loadMax():-           try               FileName = concat(directory::getCurrentDirectory(), "\\max.txt"),               consult(FileName, maxDB)           catch TraceId do               exceptionDumper(TraceId),               stdIO::writef("\n\n")           end try.                       clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         loadMax(),         getAllMax(MaxList).       predicates     onSimpanClick : button::clickResponder. clauses     onSimpanClick(_Source) = button::defaultAction :-         _ = login::display(getParent()).         getAllMax(MaxList) :-         findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) = list::nth(Cpt,MaxList)     end foreach. getAllMax([]) :-         vpiCommonDialogs::error("database is empty").
but, there is an error :
c530: The object member 'mem_max_list' is used in the class predicate

is it because i declare it twice?
Daniel

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 31 Oct 2011 11:21

this error can result from trying to access an object fact from a class predicate but do not use ther object's identifier.

I had a lot of trouble with this (keeping objects and class separate) when I first started using VIP 7.

if the fact is in the object you access it with objectId : fact (or predicate) and if it is in the class, you access it via class :: fact (or predicte)

the above also assumes you have properly declared these things in the class and interface files.
AI Rules!
P.

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 31 Oct 2011 15:52

Paul Cerkez wrote:this error can result from trying to access an object fact from a class predicate but do not use ther object's identifier.

I had a lot of trouble with this (keeping objects and class separate) when I first started using VIP 7.

if the fact is in the object you access it with objectId : fact (or predicate) and if it is in the class, you access it via class :: fact (or predicte)

the above also assumes you have properly declared these things in the class and interface files.
So, what should i do? is it delete the fact or how?
Daniel

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

Unread post by Tonton Luc » 31 Oct 2011 16:40

Hi,
Maybe try to add "class" in your code as follow :

Code: Select all

class facts     input1 : real := 0.0. %fact variable     input2 : real := 0.0. %fact variable     input3 : real := 0.0. %fact variable     input4 : real := 0.0. %fact variable     input5 : real := 0.0. %fact variable     input6 : real := 0.0. %fact variable     input7 : real := 0.0. %fact variable     input8 : real := 0.0. %fact variable     input9 : real := 0.0. %fact variable     input10 : real := 0.0. %fact variable     input11 : real := 0.0. %fact variable     input12 : real := 0.0. %fact variable     input13 : real := 0.0. %fact variable     input14 : real := 0.0. %fact variable     input15 : real := 0.0. %fact variable     input16 : real := 0.0. %fact variable    mem_max_list:real_list:=[ input1,  input2,  input3,  input4,  input5 , input6,  input7,  input8,  input9,  input10,  input11,  input12,  input13,  input14,  input15,  input16].

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 1 Nov 2011 2:46

Tonton Luc wrote:Hi,
Maybe try to add "class" in your code as follow :

Code: Select all

class facts     input1 : real := 0.0. %fact variable     input2 : real := 0.0. %fact variable     input3 : real := 0.0. %fact variable     input4 : real := 0.0. %fact variable     input5 : real := 0.0. %fact variable     input6 : real := 0.0. %fact variable     input7 : real := 0.0. %fact variable     input8 : real := 0.0. %fact variable     input9 : real := 0.0. %fact variable     input10 : real := 0.0. %fact variable     input11 : real := 0.0. %fact variable     input12 : real := 0.0. %fact variable     input13 : real := 0.0. %fact variable     input14 : real := 0.0. %fact variable     input15 : real := 0.0. %fact variable     input16 : real := 0.0. %fact variable    mem_max_list:real_list:=[ input1,  input2,  input3,  input4,  input5 , input6,  input7,  input8,  input9,  input10,  input11,  input12,  input13,  input14,  input15,  input16].
can you explain the different between "class facts" and "facts"?

Code: Select all

class facts - maxDB     max : (real Max).       class facts     input1 : real := 0.0. %fact variable     input2 : real := 0.0. %fact variable     input3 : real := 0.0. %fact variable     input4 : real := 0.0. %fact variable     input5 : real := 0.0. %fact variable     input6 : real := 0.0. %fact variable     input7 : real := 0.0. %fact variable     input8 : real := 0.0. %fact variable     input9 : real := 0.0. %fact variable     input10 : real := 0.0. %fact variable     input11 : real := 0.0. %fact variable     input12 : real := 0.0. %fact variable     input13 : real := 0.0. %fact variable     input14 : real := 0.0. %fact variable     input15 : real := 0.0. %fact variable     input16 : real := 0.0. %fact variable     mem_max_list:real_list:=[ input1,  input2,  input3,  input4,  input5 , input6,  input7,  input8,  input9,  input10,  input11,  input12,  input13,  input14,  input15,  input16].   clauses      loadMax():-           try               FileName = concat(directory::getCurrentDirectory(), "\\max.txt"),               consult(FileName, maxDB)           catch TraceId do               exceptionDumper(TraceId),               stdIO::writef("\n\n")           end try.                       clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         loadMax(),         getAllMax(MaxList).   predicates     onSimpanClick : button::clickResponder. clauses     onSimpanClick(_Source) = button::defaultAction :-         _ = login::display(getParent()).         getAllMax(MaxList) :-         findAll(Max, max(Max), MaxList),     foreach Cpt = std::fromTo(0,list::length(MaxList)-1) do         hasDomain(real,X),         list::nth(Cpt,mem_max_list) = list::nth(Cpt,MaxList)     end foreach. getAllMax([]) :-         vpiCommonDialogs::error("database is empty").
error c504: The expression has type '::real', which is incompatible with the type '::string'

what must i do with the "Max", is it real or string or what?
Daniel

Post Reply