Prolog consults - a standard? 
Author Message
 Prolog consults - a standard?

Dear Prolog Users,

Having tried to consult a predicate such as

        memberH1( Key(Value0,Rest), Key(Value1,Rest) ) :-
                !, Value0 = Value1.

(for those of you who are unsure what the problem is, all versions do not
like 'Key' being a variable).

into 3 different versions of Prolog, does anyone have any idea what the
Prolog standard is for this. i.e. where a functor is a variable?

(tjm may recognise this predicate!)

Andrew.

---------------------------------------------------------------------------
Andrew Wenn          Victoria University of Technology
                     Footscray Campus.

                     phone 03 688 4342
                     fax   03 688 4804
---------------------------------------------------------------------------



Wed, 16 Aug 1995 13:04:31 GMT  
 Prolog consults - a standard?

Quote:

>    memberH1( Key(Value0,Rest), Key(Value1,Rest) ) :-
>            !, Value0 = Value1.

>(for those of you who are unsure what the problem is, all versions do not
>like 'Key' being a variable).

>into 3 different versions of Prolog, does anyone have any idea what the
>Prolog standard is for this. i.e. where a functor is a variable?

The above is not portable.
Instead of the above, use the following:

        memberH1( Term1, Term2 ) :-
                Term0 =.. [Key, Value0, Rest],
                Term1 =.. [Key, Value1, Rest],
                !, Value0 = Value1.

or equivalently (but slightly more efficient in most implementations):

        memberH1( Term1, Term2 ) :-
                functor(Term0, Key),
                functor(Term1, Key),
                arg(2, Term0, Rest),
                arg(2, Term1, Rest),
                !,
                arg(1, Term0, Value),
                arg(1, Term1, Value).

If you want to match any number of arguments with 'Rest' instead of
just one, use
        memberH1( Term1, Term2 ) :-
                Term0 =.. [Key, Value0 | Rest],
                Term1 =.. [Key, Value1 | Rest],
                !, Value0 = Value1.

P.S. If there is only this one clause in the predicate, then you don't
     need to use the cut. If there are other clauses, you are still
     probably much better off using '->' rather than '!'.
     Cuts: just say NO! :-)

--

This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!



Thu, 17 Aug 1995 11:06:48 GMT  
 Prolog consults - a standard?

Normally, Prolog does _not_ allow variable functors such as X(Y,Z).
Implementations that do are quite exceptional.
--

:-  Artificial Intelligence Programs       phone 706 542-0358 :  *********
:-  The University of Georgia                fax 706 542-0349 :   *  *  *
:-  Athens, Georgia 30602-7415 U.S.A.     amateur radio N4TMI :  ** *** **



Fri, 18 Aug 1995 00:36:06 GMT  
 Prolog consults - a standard?

Quote:

>Normally, Prolog does _not_ allow variable functors such as X(Y,Z).
>Implementations that do are quite exceptional.

The quintus library includes a portable read implementation which treats
X(Y,Z) as shorthand for call(X,Y,Z).  I guess all you need then is a Prolog
which supports call/n.

mike

--

--
  .  

. O _   The Unicycling Postgrad                                 /      *
_/=/    CIT, Griffith University, Nathan, QLD, AUSTRALIA, 4111  \_.--._/



Sat, 19 Aug 1995 08:28:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. DCGs and consult in the ISO Prolog standard

2. Translator from standard PROLOG to Visual Prolog?

3. PDC Prolog/Visual Prolog and ISO Standards

4. A Prolog consulting job in Colorado

5. prolog consulting position available

6. consulting disc from a prolog program

7. SICStus Prolog singleton warnings slow down while consulting a file

8. NYC VMS Fortran Consulting Opportunities, Spectrum Concepts Consulting Corp

9. Syntax standard for Prolog Implementaions

10. Prolog-C Interface: standard?

11. Standard prolog

12. Prolog description/standard wanted

 

 
Powered by phpBB® Forum Software