Create a gist now

Instantly share code, notes, and snippets.

Embed
/*
* This is a prolog code showing basic code patterns
* on how to write relationships between items and
* how to reason about them.
*/
has(jack,apples). % jack has apples.
has(jack,plums). % jack has plums.
has(ann,plums). % ann has plums.
has(dan,money). % dan has money.
fruit(apples). % apple is fruit.
fruit(plums). % plums is fruit.
/*
* usage: swipl -q -f prolog_listing.pl -t fruit_listing
*/
fruit_listing :-
listing(fruit), nl, halt.
/*
* usage: swipl -q -f prolog_listing.pl -t fruit_listing
*/
main :-
has(X,apples), % who has apples
has(Y,money), % who has money
write(X), % write apple owner
put(10), % new line
write(Y), % write money owner
nl, halt. % new line and halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment