| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi if i have the following predicate defined: foo(A,B,C) :- do something is it possible to get the internal name of A something like G367 as a value (atom). The goal of this is, to then use: nb_setval(+Name, +Value) --> foo(A,B,C) :- get_internal_name(A, Name), nb_setval(Name, A), .... Thanks in advance Daniel |
|
#2
| |||
| |||
| On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: > Hi > > if i have the following predicate defined: > > foo(A,B,C) :- do something > > is it possible to get the internal name of A something like G367 as a value > (atom). You want the G367? That is just an address. Its isn't even stable, see what happens if you run the garbage collector: all numbers change. > The goal of this is, to then use: > > nb_setval(+Name, +Value) > --> foo(A,B,C) :- get_internal_name(A, Name), nb_setval(Name, A), .... Maybe you should describe the purpose of that at a higher level and someone can point at another route to solve it. Cheers --- Jan |
|
#3
| |||
| |||
| Hi Jan thanks for your reply. This is what the current actual code looks like: nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), jpl_new( nodeFieldValConnector.NodeFieldVal', [], Class), nodeFieldVal(Class, Field, Row, Content). nodeFieldVal(Class, Field, Row, Content) :- jpl_is_object(Class), prepareParams(Field, Row, Content, Params), jpl_call( Class, nodeFieldVal, Params, Return), jpl_get(Return, 'content', Content), jpl_get(Return, 'row', Row). My goal is to reuse the same Class object for all backtracking steps. Unfortuanly the way it works like this is, that after the first solution is found, Class is a free variable again and jpl_is_object(Class) which ends the whole backtracking process. It is also important that the same java class instance is used for one backtracking session because of the class internal session handling. My approach was the following: nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), jpl_new( NodeFieldVal', [], Class), nb_setval('class', Class), nodeFieldVal(Class, Field, Row, Content). nodeFieldVal(Class, Field, Row, Content) :- nb_getval('class', Class), jpl_is_object(Class), prepareParams(Field, Row, Content, Params), jpl_call( Class, nodeFieldVal, Params, Return), jpl_get(Return, 'content', Content), jpl_get(Return, 'row', Row). This works as far as there is only one nodeFieldVal query (only for some reasons ?:-nodeFieldVal(_, 'test_field', _, X) which should give all 15 entreis in test_field only returns 2 and then stops the backtracking process) But querys like ?:- nodeFieldVal(_, 'test_field1', _, X), nodeFieldVal(_, 'test2_field', _, X) would fail since they use the same java class instance (and thus the same session) even though they would have to use 2. Thats why i wanted to save the class instance in a global variable that is named after the address. Does this clarify my problem? best regards Daniel "Jan Wielemaker" <jan@nospam.ct.xs4all.nl> wrote in message news:slrng9lekp.89p.jan@ct.lan... > On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: >> Hi >> >> if i have the following predicate defined: >> >> foo(A,B,C) :- do something >> >> is it possible to get the internal name of A something like G367 as a >> value >> (atom). > > You want the G367? That is just an address. Its isn't even stable, > see what happens if you run the garbage collector: all numbers change. > >> The goal of this is, to then use: >> >> nb_setval(+Name, +Value) >> --> foo(A,B,C) :- get_internal_name(A, Name), nb_setval(Name, A), .... > > Maybe you should describe the purpose of that at a higher level and > someone can point at another route to solve it. > > Cheers --- Jan |
|
#4
| |||
| |||
| On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: You code is a bit unreadable stretched to the right of my newsreader, but from what I understand, the idea is a bit similar to this problem: %% term_in_file(+File, ?Term) is nondet. % % True if Term unifies with a term in file. term_in_file(File, Term) :- open(File, read, In), call_cleanup((repeat, read(In, Term)), close(In)). Here the stream (In) has a similar role as your result from the first jpl_new call. Hope this helps. Cheers --- Jan > thanks for your reply. > This is what the current actual code looks like: > nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), > jpl_new( > nodeFieldValConnector.NodeFieldVal', [], Class), > nodeFieldVal(Class, > Field, Row, Content). > > nodeFieldVal(Class, Field, Row, Content) :- jpl_is_object(Class), > prepareParams(Field, > Row, Content, Params), > jpl_call( > Class, nodeFieldVal, Params, Return), > jpl_get(Return, > 'content', Content), > jpl_get(Return, > 'row', Row). > > My goal is to reuse the same Class object for all backtracking steps. > Unfortuanly the way it works like this is, that after the first solution is > found, Class is a free variable again and jpl_is_object(Class) which ends > the whole backtracking process. It is also important that the same java > class instance is used for one backtracking session because of the class > internal session handling. > > My approach was the following: > nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), > jpl_new( > NodeFieldVal', [], Class), > nb_setval('class', > Class), > nodeFieldVal(Class, > Field, Row, Content). > > nodeFieldVal(Class, Field, Row, Content) :- nb_getval('class', Class), > jpl_is_object(Class), > prepareParams(Field, > Row, Content, Params), > jpl_call( > Class, nodeFieldVal, Params, Return), > jpl_get(Return, > 'content', Content), > jpl_get(Return, > 'row', Row). > > This works as far as there is only one nodeFieldVal query (only for some > reasons ?:-nodeFieldVal(_, 'test_field', _, X) which should give all 15 > entreis in test_field only returns 2 and then stops the backtracking > process) > > But querys like ?:- nodeFieldVal(_, 'test_field1', _, X), nodeFieldVal(_, > 'test2_field', _, X) > would fail since they use the same java class instance (and thus the same > session) even though they would have to use 2. Thats why i wanted to save > the class instance in a global variable that is named after the address. > > Does this clarify my problem? > > best regards > Daniel > > "Jan Wielemaker" <jan@nospam.ct.xs4all.nl> wrote in message > news:slrng9lekp.89p.jan@ct.lan... >> On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: >>> Hi >>> >>> if i have the following predicate defined: >>> >>> foo(A,B,C) :- do something >>> >>> is it possible to get the internal name of A something like G367 as a >>> value >>> (atom). >> >> You want the G367? That is just an address. Its isn't even stable, >> see what happens if you run the garbage collector: all numbers change. >> >>> The goal of this is, to then use: >>> >>> nb_setval(+Name, +Value) >>> --> foo(A,B,C) :- get_internal_name(A, Name), nb_setval(Name, A), .... >> >> Maybe you should describe the purpose of that at a higher level and >> someone can point at another route to solve it. >> >> Cheers --- Jan > |
|
#5
| |||
| |||
| Hi Jan thanks for your reply. Unfortunatly I don't quite understand our hint. Let me paraphrase the problem on a more abstract level: check(Class, Field, Value) Upon the first call of check, Class should be unified with a value that it should hold during all subsequent backtracking steps. check_it :- check(Class1, 'field1', Value), check(Class2, 'field2', Value). So here Class1 should be one value during the backtracking of all possible solutions and Class 2 should have a different value, but also hold this value during the whole process. Thank you very much for your help Jan Best regards Daniel "Jan Wielemaker" <jan@nospam.ct.xs4all.nl> wrote in message news:slrng9lrqr.9n0.jan@ct.lan... > On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: > > You code is a bit unreadable stretched to the right of my newsreader, but > from what I understand, the idea is a bit similar to this problem: > > %% term_in_file(+File, ?Term) is nondet. > % > % True if Term unifies with a term in file. > > term_in_file(File, Term) :- > open(File, read, In), > call_cleanup((repeat, read(In, Term)), close(In)). > > Here the stream (In) has a similar role as your result from > the first jpl_new call. Hope this helps. > > Cheers --- Jan > > >> thanks for your reply. >> This is what the current actual code looks like: >> nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), >> >> jpl_new( >> nodeFieldValConnector.NodeFieldVal', [], Class), >> >> nodeFieldVal(Class, >> Field, Row, Content). >> >> nodeFieldVal(Class, Field, Row, Content) :- jpl_is_object(Class), >> >> prepareParams(Field, >> Row, Content, Params), >> >> jpl_call( >> Class, nodeFieldVal, Params, Return), >> >> jpl_get(Return, >> 'content', Content), >> >> jpl_get(Return, >> 'row', Row). >> >> My goal is to reuse the same Class object for all backtracking steps. >> Unfortuanly the way it works like this is, that after the first solution >> is >> found, Class is a free variable again and jpl_is_object(Class) which ends >> the whole backtracking process. It is also important that the same java >> class instance is used for one backtracking session because of the class >> internal session handling. >> >> My approach was the following: >> nodeFieldVal(Class, Field, Row, Content) :- not(jpl_is_object(Class)), >> >> jpl_new( >> NodeFieldVal', [], Class), >> >> nb_setval('class', >> Class), >> >> nodeFieldVal(Class, >> Field, Row, Content). >> >> nodeFieldVal(Class, Field, Row, Content) :- nb_getval('class', Class), >> >> jpl_is_object(Class), >> >> prepareParams(Field, >> Row, Content, Params), >> >> jpl_call( >> Class, nodeFieldVal, Params, Return), >> >> jpl_get(Return, >> 'content', Content), >> >> jpl_get(Return, >> 'row', Row). >> >> This works as far as there is only one nodeFieldVal query (only for some >> reasons ?:-nodeFieldVal(_, 'test_field', _, X) which should give all 15 >> entreis in test_field only returns 2 and then stops the backtracking >> process) >> >> But querys like ?:- nodeFieldVal(_, 'test_field1', _, X), nodeFieldVal(_, >> 'test2_field', _, X) >> would fail since they use the same java class instance (and thus the same >> session) even though they would have to use 2. Thats why i wanted to save >> the class instance in a global variable that is named after the address. >> >> Does this clarify my problem? >> >> best regards >> Daniel >> >> "Jan Wielemaker" <jan@nospam.ct.xs4all.nl> wrote in message >> news:slrng9lekp.89p.jan@ct.lan... >>> On 2008-08-07, Daniel Funke <daniel.funke@stud.uni-karlsruhe.de> wrote: >>>> Hi >>>> >>>> if i have the following predicate defined: >>>> >>>> foo(A,B,C) :- do something >>>> >>>> is it possible to get the internal name of A something like G367 as a >>>> value >>>> (atom). >>> >>> You want the G367? That is just an address. Its isn't even stable, >>> see what happens if you run the garbage collector: all numbers change. >>> >>>> The goal of this is, to then use: >>>> >>>> nb_setval(+Name, +Value) >>>> --> foo(A,B,C) :- get_internal_name(A, Name), nb_setval(Name, A), .... >>> >>> Maybe you should describe the purpose of that at a higher level and >>> someone can point at another route to solve it. >>> >>> Cheers --- Jan >> |
|
#6
| |||
| |||
| On Thu, 07 Aug 2008 15:10:12 +0200, Daniel Funke wrote: > Hi Jan > > thanks for your reply. Unfortunatly I don't quite understand our hint. > > Let me paraphrase the problem on a more abstract level: > > check(Class, Field, Value) > > Upon the first call of check, Class should be unified with a value that > it should hold during all subsequent backtracking steps. > > check_it :- check(Class1, 'field1', Value), check(Class2, 'field2', > Value). > > So here Class1 should be one value during the backtracking of all > possible solutions and Class 2 should have a different value, but also > hold this value during the whole process. Maybe what you want can be described as check_it :- fixvalue1(Class1), fixvalue2(Class2), check(Class1, 'field1', Value), check(Class2, 'field2',Value). The bindings for Class* are not changed during the backtracking inside check/3. Cheers Bart Demoen |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.