I am not an expert on the latest version of VIP (still need to upgrade from 7.5) but looking at your code block the logic looks iffy.
(Assuming hierarchy_PART(...) and local_object(...) are fact bases)
To see it, try re-ordering the clauses;
Code: Select all
add_local_conditionally(Module_name, In_local_list, In_local_entry, Out_list, Last_entry) :-
hierarchy_PART(1, Top_package_module, 0, _, _, _, _), % PSC - will always succeed assuming a record exists
local_object(local_OBJECT(Module_name, In_local_entry, _, Object_name, _, _, _, _, _)), % PSC - will always succeed assuming a record exists for that Module_name AND In_local_entry. The AND here is important.
local_object(local_OBJECT(Top_package_module, _, _, Object_name, _, _, _, _, _)), % PSC - will only succeed if there is a record with Top_package_module AND Object_name. The AND here is important.
% it exists also in the package
Top_package_module <> Module_name, % PSC - this is your conditional check to start backtracking. If this succeeds, move on to the assertion.
% and the current module is not the Top package
!, % PSC - moved to here
%PSC- the rest of this is the action to take once the above condition has been met.
% Next_local_list = In_local_list,
% in this case the list is not updated with this local
% PSC - so why are you creating a new variable, just use the existing one?
Next_local_entry = In_local_entry + 1,
% not needed until you are ready to assert the new fact.
get_and_append_local(Module_name, In_local_list, Next_local_entry, Out_list, Last_entry).
Some things to think about:
What happens when there is no entry for hierarchy_PART(...)? If you do not have a 'graceful fail' clause to account for that, the program will fail all the up until there is one (a 'graceful fail' ) or it crashes.
What happens when there is no Module_name entry in local_Object? That would be your first failure. Do you have a graceful fail clause to catch that?
What happens when the Module _name submitted actually is the Top_package_module. Do you have a graceful fail clause to catch that?
What happens when nothing meets your conditions? Do you have a graceful fail clause to catch that?
In this search, is Object_Name really needed? You already know the Top_Package_module and the Module_name.
Can a Module have more than one Object_name or can Object_name be associated with more than one module?
- If not, is Object_name really needed in this search?
If Object_name and Module_Name are 1:1, then comment out the local_object(Top_module_name ...) clause.
If a module can have more than one object associated with it then do not comment it out.
Also, if an Object_name can be associated with more than one module, do not comment it out.