Re: retrieve functor name knowing its parameters
"Richard A. O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 21/11/2013, at 10:24 AM, adnan wrote: > How I can retrieve functor name knowing its parameters , my functors are > dynamic and not staic I tried this code Fun=..[Functor,1,2],call(Fun). But I > got error of not sufficient instanciation .Is there another possible way to > have it? I am having trouble understanding what you want here. A functor is NOTHING OTHER THAN a pair of an atom and a non-negative integer. The atom is the function name. The non-negative integer is its arity. If you have an atom and you have a non-negative integer then you have all the information there could possibly be to be a functor; there is nothing else to "retrieve". In the "univ" call Fun =.. [Functor,1,2] the one thing that the variable "Functor" cannot possibly be is a functor. It MUST be an atom. (The "Fun" variable will be a compound term, to which the word "Fun" isn't really appropriate either.) Name = fred, Term =.. [Name,1,2] => Term = fred(1,2). What significance, _if any_, the resulting term has is up to you. In a call to univ, Term =.. List, there are basically two cases: (1) Term is not a variable. A list is computed from Term and unified with List. (2) Term is a variable, List is a non-empty proper list, and either List = [Num] for some number Num or the first element of List is an atom. If you have var(Term), var(Name), Term =.. [Name,1,2] then you will get an instantiation error, because the set of possible Names that would make this true is infinite. In particular, there is here *NO* connection with the *predicates* in your program. A functor is a functor is a functor whatever predicates you have. You don't have a potzremie/3 predicate? Tough, potzremie(a,b,c) is still a perfectly good data structure (term), and potzremie/3 is still a perfectly good functor. If it so happens that you _are_ wanting to deal with predicates, be aware that predicates are named by *triples* Module:Name/Arity, not by simple functors, and also be aware that you almost surely *don't* want to call arbitrary predicates. The simplest and cleanest thing for you to do may be to maintain a table of the predicates you definitely *do* want to refer to in this way.