I’m using: SWI-Prolog version 8.3.9
I want the code to: make private user defined functions visible to all predicates within the module.
But what I’m getting is: ERROR: Unknown procedure: aDict:private_udf_1/2
My code looks like this:
% demo/test modules, dicts, ordinary predicates, udfs, public/private
% call tree
% user
% public 1
% public 2
% private 1
% public 2
% private 2
% The call tree is implemented with ordinary predicates and with user defined functions.
% Works as expected for the ordinary predicates.
% Fails on public 1 to private 1 with user defined functions.
:- module(aModule,[pred_tester/0, public_pred_1/0,public_pred_2/0,
udf_tester/0, public_udf_1 /2,public_udf_2 /2
]).
%% helper
printnl(X) :- print(X),nl.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% pred tests
pred_tester() :-
printnl(pred_tester():'trying user to public_pred_1()' ),
public_pred_1(),
printnl(pred_tester():'sucessful user to aModule public_pred_1()' ).
public_pred_1() :-
printnl(public_pred_1():' trying public_pred_1() to public_pred_2()' ),
public_pred_2(),
printnl(public_pred_1():' successful public_pred_1() to public_pred_2()' ),
printnl(public_pred_1():' trying public_pred_1() to private_pred_1()' ),
private_pred_1(),
printnl(public_pred_1():' successful public_pred_1() to private_pred_1()' ).
private_pred_1() :-
printnl(private_pred_1():' trying private_pred_1() to public_pred_2()' ),
public_pred_2(),
printnl(private_pred_1():' successful private_pred_1() to public_pred_2()' ),
printnl(private_pred_1():' trying private_pred_1() to private_pred_2()' ),
private_pred_2(),
printnl(private_pred_1():' successful private_pred_1() to private_pred_2()' ).
public_pred_2() :- true.
private_pred_2() :- true.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% udf tests
udf_tester() :-
printnl(udf_tester():'trying user to public_udf_1()' ),
aDict{}.public_udf_1() = true,
printnl(udf_tester():'sucessful user to aModule public_udf_1()' ).
aDict{}.public_udf_1() := true :-
printnl(public_udf_1():' trying public_udf_1() to public_udf_2()' ),
aDict{}.public_udf_2() = true,
printnl(public_udf_1():' successful public_udf_1() to public_udf_2()' ),
printnl(public_udf_1():' trying public_udf_1() to private_udf_1()' ),
aDict{}.private_udf_1() = true,
printnl(public_udf_1():' successful public_udf_1() to private_udf_1()' ).
aDict{}.private_udf_1() := true :-
printnl(private_udf_1():' trying private_udf_1() to public_udf_2()' ),
aDict{}.public_udf_2() = true,
printnl(private_udf_1():' successful private_udf_1() to public_udf_2()' ),
printnl(private_udf_1():' trying private_udf_1() to private_udf_2()' ),
aDict{}.private_udf_2() = true,
printnl(private_udf_1():' successful private_udf_1() to private_udf_2()' ).
aDict{}.public_udf_2() := true :- true.
aDict{}.private_udf_2() := true :- true.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/* Results
?- pred_tester().
pred_tester():'trying user to public_pred_1()'
public_pred_1():' trying public_pred_1() to public_pred_2()'
public_pred_1():' successful public_pred_1() to public_pred_2()'
public_pred_1():' trying public_pred_1() to private_pred_1()'
private_pred_1():' trying private_pred_1() to public_pred_2()'
private_pred_1():' successful private_pred_1() to public_pred_2()'
private_pred_1():' trying private_pred_1() to private_pred_2()'
private_pred_1():' successful private_pred_1() to private_pred_2()'
public_pred_1():' successful public_pred_1() to private_pred_1()'
pred_tester():'sucessful user to aModule public_pred_1()'
true.
?- udf_tester().
udf_tester():'trying user to public_udf_1()'
public_udf_1():' trying public_udf_1() to public_udf_2()'
public_udf_1():' successful public_udf_1() to public_udf_2()'
public_udf_1():' trying public_udf_1() to private_udf_1()'
ERROR: Unknown procedure: aDict:private_udf_1/2
ERROR: In:
ERROR: [16] aDict:private_udf_1(aDict{},_37846)
ERROR: [15] eval_dict_function(private_udf_1(),aDict,aDict{},_37880) at /Applications/SWI-Prolog.app/Contents/swipl/boot/dicts.pl:85
ERROR: [13] aModule:public_udf_1(aDict{},true) at /Users/rgb/Documents/Software Development/Computational CT/Latest/beta/module and dict test 4.pl:56
ERROR: [12] eval_dict_function(public_udf_1(),aDict,aDict{},true) at /Applications/SWI-Prolog.app/Contents/swipl/boot/dicts.pl:85
ERROR: [10] aModule:udf_tester at /Users/rgb/Documents/Software Development/Computational CT/Latest/beta/module and dict test 4.pl:50
ERROR: [9] toplevel_call(user:user: ...) at /Applications/SWI-Prolog.app/Contents/swipl/boot/toplevel.pl:1113
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
Exception: (16) aDict:private_udf_1(aDict{}, _37038) ?
*/