Amine Marref a écrit :
Hi,I use a meta-interpreter in my program. The meta-interpreter needs to check whether a particular predicate is built-in or user-defined to perform an iterative deepening DFS...... solve(A,_,_):- predicate_property(A, built_in), !, call(A). solve(A,D,Limit):- predicate_property(A, user), clause(A,B), D1 is D+1, solve(B,D1,Limit). ....The above code works with Sicstus for instance. However, GNU Prolog needs A to be a predicate indicator e.g. length/2 and not a goal.so: | ?- predicate_property(length/2, built_in). yes | ?- predicate_property(length([a,b],2), built_in).uncaught exception: error(type_error(predicate_indicator,length([a,b],2)),predicate_property/2)My question is then: how do I go from the goal length([a,b],2) to the predicate indicator length/2?The best I could do was:| ?- functor(length([a,b],2), Functor, Arity), atom_concat(Functor,/,Temp), number_atom(Arity, Arity1), atom_concat(Temp, Arity1, Predicate_Indicator).Arity = 2 Arity1 = '2' Functor = length Predicate_Indicator = 'length/2' Temp = 'length/' yes However, 'length/2' does not work as first argument to predicate_property. Any help? Amine.
Hi Amine, Try this : | ?- functor(length([a,b],2), Functor, Arity),Predicate_Indicator =.. ['/',Functor, Arity], predicate_property(Predicate_Indicator, built_in).
Arity = 2 Functor = length Predicate_Indicator = length/2 yesPredicate_Indicator is not an atom but must be a compound term '/'(Functor,Arity). That's why I use the "univ" predicate (=..) to build the term :
| ?- predicate_property('length/2', built_in).
uncaught exception:
error(type_error(predicate_indicator,'length/2'),predicate_property/2)
| ?- predicate_property('/'(length,2), built_in).
yes
| ?- predicate_property(length/2, built_in).
yes
Good luck!
--
Ali ED-DBALI
_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog
