Unification of a variable for several backtracking steps

This is a discussion on Unification of a variable for several backtracking steps within the PROLOG forums in Programming Languages category; Hi i have the following problem in SWI-Prolog. I have a Java Class (NodeFieldVal) that is retrieving Information from a backend system. When my predicate nodeFieldVal is first used, Class is not assigned and the first rule matches, therefore a class will be instantiated. Then the second rule matches and actually calls the method to retrieve data. ?- nodeFieldVal(_, 'SCARR.CARRID', _, X). X = 'AA' ; false. When I issue the above query i would suspect that X should be unificated with all possible CARRIDs in SCARR (there are like 35). Instead I only receive one. (The session handling is ...

Go Back   Application Development Forum > Programming Languages > PROLOG

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-06-2008, 11:11 AM
Daniel Funke
Guest
 
Default Unification of a variable for several backtracking steps

Hi

i have the following problem in SWI-Prolog. I have a Java Class
(NodeFieldVal) that is retrieving Information from a backend system.

When my predicate nodeFieldVal is first used, Class is not assigned and the
first rule matches, therefore a class will be instantiated. Then the second
rule matches and actually calls the method to retrieve data.

?- nodeFieldVal(_, 'SCARR.CARRID', _, X).
X = 'AA' ;
false.

When I issue the above query i would suspect that X should be unificated
with all possible CARRIDs in SCARR (there are like 35). Instead I only
receive one. (The session handling is done inside the Java class).

After I traced the execution, I stumbeld upon the reason: After the first
result has been found, Class is free again, thus jpl_is_object(Class) fails
which ends the backtracking process.

The QUESTION is: Is it possible to unificate Class so that it will be bound
for more than one recursion step, thus retrieving all values from SCARR?

Best regards
Daniel

CODE:
:- use_module(library(jpl)).

prepareParams(Field, Row, Content, [Field, Row, Content]) :- nonvar(Row),
nonvar(Content).
prepareParams(Field, Row, Content, [Field, 0, Content]) :- var(Row),
nonvar(Content).
prepareParams(Field, Row, Content, [Field, Row, @(null)]) :- nonvar(Row),
var(Content).
prepareParams(Field, Row, Content, [Field, 0, @(null)]) :- var(Row),
var(Content).

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).

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:47 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.