Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- export(functor_safe/3).
- functor_safe(P,F,A):- catch(compound_name_arity(P,F,A),_,functor_safe_1(P,F,A)).
- % functor_safe_0(P,F,A):-var(P),A==0,compound_name_arguments(P,F,[]),!.
- % bin-prolog
- functor_safe_0(P,F,A):-var(P),A==0,!,P=F,!,warn_bad_functor(P).
- functor_safe_0(P,F,A):-functor_safe_1(P,F,A),!.
- functor_safe_1(M:P,M:F,A):-var(P),atom(M),functor_catch(P,F,A),!,warn_bad_functor(F).
- functor_safe_1(P,F,A):-var(P),strip_f_module(F,F0),functor_catch(P,F0,A),!,warn_bad_functor(F).
- functor_safe_1(P,F,A):-compound(P),!,functor_safe_compound(P,F,A),warn_bad_functor(F).
- functor_safe_1(P,F,0):- hotrace(STRING(P);atomic(P)), atom_string(F,P),warn_bad_functor(F).
- functor_safe_compound((_,_),',',2).
- functor_safe_compound([_|_],'.',2).
- functor_safe_compound(_:P,F,A):- functor_catch(P,F,A),!.
- functor_safe_compound(P,F,A):- functor_catch(P,F,A).
- functor_safe_compound(P,F,A):- var(F),strip_f_module(P,P0),!,functor_catch(P0,F0,A),strip_f_module(F0,F),!.
- functor_safe_compound(P,F,A):- strip_f_module(P,P0),strip_f_module(F,F0),!,functor_catch(P0,F0,A).
- 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