Search code examples
prologswi-prolog

Prolog functor , swi-prolog


Check if the predicate functor(Term, F, A) succeeds if Term has functor F and arity A by defining a functor

The code I've tried is

likes(Mary,pizza)

Is this correct?


Solution

  • As described at https://www.swi-prolog.org/pldoc/man?predicate=functor/3

    ?- functor(likes('Mary', pizza), Name, Arity).
    Name = likes,
    Arity = 2.
    
    ?- functor(Term, likes, 2).
    Term = likes(_,_).
    

    Beware: Variables start with a capital letter, so the value Mary is 'Mary', because Mary is instead a reference to a variable.