Re: predicate_property help.

Paulo Moura <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
On 2007/10/02, at 15:20, Amine Marref wrote:

> 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.

True.

> 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.

Of course not, 'length/2' is an atom. Try:

| ?- functor(length([a,b],2), Functor, Arity), predicate_property 
(Functor/Arity, built_in).

All the best,

Paulo


-----------------------------------------------------------------
Paulo Jorge Lopes de Moura
Dep. of Computer Science, University of Beira Interior
6201-001 Covilhã, Portugal

Office 4.3  Ext. 3257
Phone: +351 275319891 Fax: +351 275319899
Email: <mailto:[email protected]>

Home page: <http://www.di.ubi.pt/~pmoura>
Research: <http://logtalk.org/>
-----------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.