new to prolog - need help 
Author Message
 new to prolog - need help

I need to relate a structure to another structure i this way:

thing(K,S):-
    relation(K),
    secondrelation(S).

largerthing([thing(A,B),thing(C,D).........]).

how do i get the larger thing to see the relationship for the other
thing without going through and saying relation(A),
relation(C).....etc??

this is for SWI-prolog

Ta



Mon, 18 Feb 2002 03:00:00 GMT  
 new to prolog - need help
Dear Karen,

Quote:
> I need to relate a structure to another structure i this way:

> thing(K,S):-
>     relation(K),
>     secondrelation(S).

> largerthing([thing(A,B),thing(C,D).........]).

> how do i get the larger thing to see the relationship for the other
> thing without going through and saying relation(A), relation(C).....etc??

There is a difference between structures and predicates. Your first use of "thing" is as a predicate. In the predicate "largerthing" you have a structure (a list) with members which are structures (things). It's OK to use the same name for predicates and structures, but keep in mind which is which.

One question you have to answer is whether the empty list is a largerstructure. If so, then

largerstructure([]).

is true.

Then you can define the predicate, largerstructure/1 (the 1 indicates the arity), like this:

largerstructure([]).
largerstructure([thing(A,B)|Things]) :-
     thing(A,B),
     largerstructure(Things).

The first clause says that the empty list is a largerstructure. The second clause says that the list, [thing(A,B)|Things], is a largerstructure if thing(A,B) is true, and Things is a largerstructure.

Note that in the second clause "thing(A,B)" appears first as a structure, second as a predicate.

If the empty list is not a largerstructure, but a list with a single thing is, then the first clause may be

largerstructure([thing(A,B)]) :- thing(A,B).

Best regards,

Bill Spight

P. S. For email remove the x.



Mon, 18 Feb 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. New to Prolog - some help please!

2. help for new Prolog-er

3. Need help in prolog, please

4. Need help with a Prolog Program

5. Help needed: Benchmarks of higher-order prolog programs?

6. Prolog newbie needs help!!

7. need help with prolog

8. Life game in prolog - need urgent help!!!!

9. non-Prolog programmer needs help

10. SWI-Prolog XPCE help needed

11. Basic prolog programming - need help

12. Need help identifying a company in Los Angeles that uses Prolog

 

 
Powered by phpBB® Forum Software