Advertisement
logicmoo

Untitled

Aug 1st, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :- export(functor_safe/3).
  2. functor_safe(P,F,A):- catch(compound_name_arity(P,F,A),_,functor_safe_1(P,F,A)).
  3. % functor_safe_0(P,F,A):-var(P),A==0,compound_name_arguments(P,F,[]),!.
  4. % bin-prolog
  5. functor_safe_0(P,F,A):-var(P),A==0,!,P=F,!,warn_bad_functor(P).
  6. functor_safe_0(P,F,A):-functor_safe_1(P,F,A),!.
  7. functor_safe_1(M:P,M:F,A):-var(P),atom(M),functor_catch(P,F,A),!,warn_bad_functor(F).
  8. functor_safe_1(P,F,A):-var(P),strip_f_module(F,F0),functor_catch(P,F0,A),!,warn_bad_functor(F).
  9. functor_safe_1(P,F,A):-compound(P),!,functor_safe_compound(P,F,A),warn_bad_functor(F).
  10. functor_safe_1(P,F,0):- hotrace(STRING(P);atomic(P)), atom_string(F,P),warn_bad_functor(F).
  11. functor_safe_compound((_,_),',',2).
  12. functor_safe_compound([_|_],'.',2).
  13. functor_safe_compound(_:P,F,A):- functor_catch(P,F,A),!.
  14. functor_safe_compound(P,F,A):- functor_catch(P,F,A).
  15. functor_safe_compound(P,F,A):- var(F),strip_f_module(P,P0),!,functor_catch(P0,F0,A),strip_f_module(F0,F),!.
  16. functor_safe_compound(P,F,A):- strip_f_module(P,P0),strip_f_module(F,F0),!,functor_catch(P0,F0,A).
  17.  
  18. functor_catch(P,F,A):- catch(functor(P,F,A),_,(trace,functor(P,F,A))).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement