Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy
Last active August 22, 2017 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinite-Joy/1cc9cb8fe1e5e0be85b162d2c75686b1 to your computer and use it in GitHub Desktop.
Save infinite-Joy/1cc9cb8fe1e5e0be85b162d2c75686b1 to your computer and use it in GitHub Desktop.
/*
* 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